coverage

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: MIT Imports: 8 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 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 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 Check

func Check(profilePath, srcRoot, modPath string) (Report, error)

Check parses the coverprofile at profilePath and returns a Report over blocks not marked for ignore. srcRoot is the module root on disk; modPath is the go.mod module path, used to map profile paths to files on disk.

A profile produced by `go test ./... -coverpkg=./...` emits each instrumented block once per test binary, so the same block recurs many times with differing counts. Blocks are first merged by identity (file + span), OR-ing the counts (mode: set), exactly as `go tool cover` does — otherwise the denominator is inflated by the duplication.

func CheckProfile

func CheckProfile(profilePath string) (Report, error)

CheckProfile resolves the module root from the working directory (nearest ancestor with a go.mod) and checks profilePath against the module sources.

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.

Jump to

Keyboard shortcuts

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