Documentation
¶
Overview ¶
Package covergate decides whether a Go cover profile covers every statement. It is the repository's coverage gate: exact (covered statements are compared with total statements, never a rounded percentage) and without any input that lowers the bar.
Index ¶
Constants ¶
const RequiredPercent = 100
RequiredPercent is the share of statements that must be covered. It is a constant on purpose: no flag, environment variable or argument changes it, and a test fails if it is anything other than 100.
Variables ¶
This section is empty.
Functions ¶
func ModulePackages ¶
ModulePackages returns the import paths of the packages of the module whose root is fsys that have a Go file that is not a test file, which is where statements are: the packages `go list ./...` lists (see walkPackages), but for those that hold test files only.
func Run ¶
func Run(args []string, stdout, stderr io.Writer, open func(string) (io.ReadCloser, error), root fs.FS) int
Run is the gate command: Run(["cover.out"], ...) prints the totals and returns 0 when every statement is covered, 1 when any is not, 2 for a usage or read error. It takes exactly one argument, the profile path. root is the module's file tree: every package of the module must be in the profile.
func TestMains ¶
TestMains returns the test files of the module that declare a TestMain, read from the source. The gate refuses every one: a TestMain that exits before it runs the tests (os.Exit(0)) leaves its package out of the profile, and one that runs them and then exits 0 (m.Run(); os.Exit(0)) hides a failing test and still leaves coverage at 100%. A file that does not parse is an error.
Types ¶
type Block ¶
Block is one statement block of a cover profile, merged across the test binaries that reported it.
type Profile ¶
type Profile struct {
Blocks []Block
}
Profile is a parsed cover profile.
func Parse ¶
Parse reads a cover profile (any mode). Repeated blocks, as when several test binaries cover the same package, are merged: a block is hit when any report of it was hit.
func (Profile) Complete ¶
Complete reports whether the covered statements reach RequiredPercent of the total, in exact integer arithmetic. A profile with no statements is never complete: an empty profile means the tests measured nothing.
func (Profile) Missing ¶
Missing returns the packages, of those given, that contribute no statement to the profile: a package whose tests were not run (a TestMain that exits, a package without tests) is absent from a profile, and the totals of the others would still read 100%.