coverage

package
v0.5.1 Latest Latest
Warning

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

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

This section is empty.

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