coverage

package
v0.41.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package coverage parses a Go coverprofile and reports statement coverage over blocks not marked with a coverage-ignore directive. It backs the awf coverage gate (ADR-0012): a directive of the form "<slashes> coverage-ignore: <reason>" drops its block from both the covered and total counts; a directive with no non-empty reason is an error.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanonicalBaseline added in v0.40.0

func CanonicalBaseline(baseline Baseline) ([]byte, error)

CanonicalBaseline validates and renders a byte-stable baseline.

func Filter added in v0.10.0

func Filter(profilePath, srcRoot, modPath string) (string, error)

Filter returns a coverprofile containing exactly the blocks of the profile at profilePath that are NOT dropped by a coverage-ignore directive - the same blocks the ADR-0012 gate holds accountable, sharing ignoredLines verbatim so the two can never disagree on what "ignored" means (ADR-0065's covered report). The output carries a "mode: set" header (the mode parseProfile discards; awf's gate profile is always set) and merged-unique blocks in deterministic (file, startLine, span) order, so it round-trips as valid Codecov input.

func FilterProfile added in v0.10.0

func FilterProfile(profilePath string) (string, error)

FilterProfile resolves the module root from the working directory and returns the profile at profilePath with its coverage-ignored blocks removed (see Filter).

Types

type Analysis added in v0.40.0

type Analysis struct {
	ModulePath           string
	Raw                  Report
	Filtered             Report
	RawMisses            []Identity
	UniverseSHA256       string
	Selectors            []Selector
	ProductionDirectives []Directive
	TestDirectives       []Directive
}

Analysis is the policy view of one merged whole-module profile and its source tree.

func Analyze added in v0.40.0

func Analyze(profilePath, srcRoot, modPath string) (Analysis, error)

Analyze parses one whole-module profile into the canonical raw policy model.

func AnalyzeProfile added in v0.40.0

func AnalyzeProfile(profilePath string) (Analysis, error)

AnalyzeProfile resolves the module root and analyzes one whole-module profile.

type Baseline added in v0.40.0

type Baseline struct {
	Version              int                  `json:"version"`
	ModulePath           string               `json:"modulePath"`
	UniverseSHA256       string               `json:"universeSHA256"`
	Repository           []MissAdmission      `json:"repository"`
	Selectors            []SelectorBaseline   `json:"selectors"`
	ProductionDirectives []DirectiveAdmission `json:"productionDirectives"`
	TestDirectives       []Directive          `json:"testDirectives"`
	PlatformDirectives   []PlatformDirective  `json:"platformDirectives"`
	EquivalentMutants    []EquivalentMutant   `json:"equivalentMutants"`
}

Baseline is the canonical generated coverage policy artifact.

func LoadBaseline added in v0.40.0

func LoadBaseline(path string) (Baseline, error)

LoadBaseline loads strict, canonical baseline evidence.

func Regenerate added in v0.40.0

func Regenerate(analysis Analysis, previous *Baseline, review Review) (Baseline, error)

Regenerate creates the next canonical policy while preserving unchanged admissions and requiring explicit review for every added or moved identity.

type Directive added in v0.40.0

type Directive struct {
	File       string `json:"file"`
	Line       int    `json:"line"`
	TargetLine int    `json:"targetLine"`
	Reason     string `json:"reason"`
	Mapped     bool   `json:"mapped"`
	Executed   bool   `json:"executed"`
}

Directive describes one coverage-ignore directive and its relationship to the measured whole-module profile.

type DirectiveAdmission added in v0.40.0

type DirectiveAdmission struct {
	Directive Directive   `json:"directive"`
	Class     IgnoreClass `json:"class"`
	Evidence  string      `json:"evidence"`
}

DirectiveAdmission records the reviewed class and evidence for one retained production directive.

type EquivalentMutant added in v0.40.0

type EquivalentMutant struct {
	File    string `json:"file"`
	Line    int    `json:"line"`
	Column  int    `json:"column"`
	Mutator string `json:"mutator"`
	Reason  string `json:"reason"`
}

EquivalentMutant is an exact independently reviewed equivalent survivor.

type Finding added in v0.40.0

type Finding struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

Finding is one blocking policy diagnostic.

func Evaluate added in v0.40.0

func Evaluate(analysis Analysis, baseline Baseline) []Finding

Evaluate compares exact current identities and directive evidence with a canonical baseline. Percentages never participate in the decision.

type Identity added in v0.40.0

type Identity struct {
	File       string   `json:"file"`
	Start      Position `json:"start"`
	End        Position `json:"end"`
	Statements int      `json:"statements"`
}

Identity is the exact identity of one coverprofile block.

type IgnoreClass added in v0.40.0

type IgnoreClass string

IgnoreClass is one admitted production coverage-ignore class.

const (
	IgnoreProcessExit        IgnoreClass = "tested-process-exit"
	IgnoreImpossibleState    IgnoreClass = "revalidated-impossible-state"
	IgnoreDeterministicFault IgnoreClass = "uninducible-deterministic-fault"
	IgnorePlatformOnly       IgnoreClass = "platform-only"
)

type MissAdmission added in v0.40.0

type MissAdmission struct {
	Identity  Identity  `json:"identity"`
	Reason    string    `json:"reason"`
	MovedFrom *Identity `json:"movedFrom,omitempty"`
}

MissAdmission records why an exact raw miss may remain in the baseline.

type PlatformDirective added in v0.40.0

type PlatformDirective struct {
	Directive Directive   `json:"directive"`
	Platforms []string    `json:"platforms"`
	Class     IgnoreClass `json:"class"`
	Evidence  string      `json:"evidence"`
}

PlatformDirective records a source directive that the host profile cannot measure.

type Position added in v0.40.0

type Position struct {
	Line   int `json:"line"`
	Column int `json:"column"`
}

Position identifies a line and column in a Go source file.

type Report

type Report struct {
	Covered int // statements in non-ignored blocks executed at least once
	Total   int // statements in non-ignored blocks
}

Report is the result of checking a coverprofile.

func (Report) OK

func (r Report) OK() bool

OK reports whether every non-ignored statement is covered.

func (Report) Percent

func (r Report) Percent() float64

Percent returns the covered percentage; an empty Report is 100.

type Review added in v0.40.0

type Review struct {
	Misses             []MissAdmission      `json:"misses"`
	Directives         []DirectiveAdmission `json:"directives"`
	PlatformDirectives []PlatformDirective  `json:"platformDirectives"`
	EquivalentMutants  []EquivalentMutant   `json:"equivalentMutants"`
}

Review supplies independently reviewed evidence for baseline changes.

func LoadReview added in v0.40.0

func LoadReview(path string) (Review, error)

LoadReview loads strict review evidence.

type Selector added in v0.40.0

type Selector struct {
	Name   string     `json:"name"`
	Roots  []string   `json:"roots"`
	Misses []Identity `json:"misses"`
}

Selector is one critical path set derived from the whole-module profile.

type SelectorBaseline added in v0.40.0

type SelectorBaseline struct {
	Name   string     `json:"name"`
	Roots  []string   `json:"roots"`
	Misses []Identity `json:"misses"`
}

SelectorBaseline is the canonical baseline view of a critical selector.

Jump to

Keyboard shortcuts

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