cover

package
v1.23.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 9 Imported by: 5 modules, 3 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cover reports coverage on modules.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NoEarlyExitEvalOptions added in v1.20.0

func NoEarlyExitEvalOptions(cov *Cover, ndbc builtins.NDBCache) []rego.EvalOption

NoEarlyExitEvalOptions is NoIndexingEvalOptions' early-exit-disabled counterpart.

func NoIndexingEvalOptions added in v1.20.0

func NoIndexingEvalOptions(cov *Cover, ndbc builtins.NDBCache) []rego.EvalOption

NoIndexingEvalOptions returns the rego.EvalOptions for a supplementary pass that traces into cov with rule indexing disabled, replaying the non-deterministic builtin results captured in ndbc.

Types

type Cover

type Cover struct {
	// contains filtered or unexported fields
}

Cover computes and reports on coverage.

func New

func New() *Cover

New returns a new Cover object.

func (*Cover) AddRun added in v1.20.0

func (c *Cover) AddRun(kind Kind, supplementary *Cover)

AddRun registers supplementary as a Cover populated by evaluating the same query with e.g. indexing or early exit disabled. In Report, any range that's NotCovered but Covered in supplementary is tagged with kind.

func (*Cover) Config

func (*Cover) Config() topdown.TraceConfig

Config returns the standard Tracer configuration for the Cover tracer

func (*Cover) Enabled

func (*Cover) Enabled() bool

Enabled returns true if coverage is enabled.

func (*Cover) Report

func (c *Cover) Report(modules map[string]*ast.Module) (report Report)

Report returns a coverage Report for the given modules.

func (*Cover) Trace deprecated

func (c *Cover) Trace(event *topdown.Event)

Trace updates the coverage state.

Deprecated: Use TraceEvent instead.

func (*Cover) TraceEvent

func (c *Cover) TraceEvent(event topdown.Event)

TraceEvent updates the coverage state.

type CoverageThresholdError

type CoverageThresholdError struct {
	Coverage  float64
	Threshold float64
	Report    *Report
}

CoverageThresholdError represents an error raised when the global code coverage percentage is lower than the specified threshold.

func (*CoverageThresholdError) Error

func (e *CoverageThresholdError) Error() string

type FileReport

type FileReport struct {
	Covered         []Range `json:"covered,omitempty"`
	NotCovered      []Range `json:"not_covered,omitempty"`
	CoveredLines    int     `json:"covered_lines,omitempty"`
	NotCoveredLines int     `json:"not_covered_lines,omitempty"`
	Coverage        float64 `json:"coverage,omitempty"`
}

FileReport represents a coverage report for a single file.

func (*FileReport) IsCovered

func (fr *FileReport) IsCovered(row int) bool

IsCovered returns true if the row is marked as covered in the report.

func (*FileReport) IsNotCovered

func (fr *FileReport) IsNotCovered(row int) bool

IsNotCovered returns true if the row is marked as NOT covered in the report. This is not the same as simply not being reported. For example, certain statements like imports are not included in the report.

type Kind added in v1.20.0

type Kind string

Kind categorizes why a Range was not covered.

const (
	// KindIndexExcluded marks a not-covered range that the rule indexer
	// excluded without attempting it.
	KindIndexExcluded Kind = "index_excluded"

	// KindEarlyExit marks a not-covered range that early-exit optimizations
	// skipped without attempting it.
	KindEarlyExit Kind = "early_exit"
)

type Position

type Position struct {
	Row int `json:"row"`
	Col int `json:"col,omitempty"`
}

Position represents a file location.

type PositionSlice deprecated

type PositionSlice []Position

PositionSlice is a collection of position that can be sorted.

Deprecated: PositionSlice is unused inside OPA and will be removed in a future release.

func (PositionSlice) Sort deprecated

func (sl PositionSlice) Sort()

Sort sorts the slice by row, then column.

Deprecated: see PositionSlice.

type Range

type Range struct {
	Start Position `json:"start"`
	End   Position `json:"end"`
	Kinds []Kind   `json:"kinds,omitempty"`
}

Range represents a range of positions in a file. Kinds categorizes why a range was not covered, e.g. KindIndexExcluded; it's empty when covered or the reason is unknown, and can hold more than one Kind.

func (Range) Compare added in v1.18.0

func (r Range) Compare(other Range) int

Compare orders ranges by start, then end, comparing row before col.

func (Range) In

func (r Range) In(row int) bool

In returns true if the row is inside the range.

type Report

type Report struct {
	Files           map[string]*FileReport `json:"files"`
	CoveredLines    int                    `json:"covered_lines"`
	NotCoveredLines int                    `json:"not_covered_lines"`
	Coverage        float64                `json:"coverage"`
}

Report represents a coverage report for a set of files.

func (Report) IsCovered

func (r Report) IsCovered(file string, row int) bool

IsCovered returns true if the row in the given file is covered.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL