covergate

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package covergate is the exact statement-coverage gate. It reads a Go cover profile and passes only when every statement in it was executed.

The gate has no threshold to configure: it compares the number of covered statements with the total number of statements, so 99.99% fails. There is no flag, environment variable or input that lowers the bar.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Missing

func Missing(pkgs []Package, perPackage map[string]int) []string

Missing returns a message for each Go file with a build constraint, for each test file that declares a TestMain, and for each package that has statements and is absent from the profile or contributes no statements to it. perPackage is the statement count of each package path in the profile.

func OSOpen

func OSOpen(name string) (io.ReadCloser, error)

OSOpen opens a profile on disk.

func Run

func Run(args []string, stdout, stderr io.Writer, open Open, packages Packages) int

Run checks the profile named by args, which must be exactly one path. It returns the process exit code: 0 when every statement is covered and every package of the module that has statements is in the profile with some, 1 when not, 2 on a usage or I/O error. Anything else on the command line, including a flag, is a usage error: the gate takes no options.

Types

type Open

type Open func(name string) (io.ReadCloser, error)

Open opens the named cover profile. Run takes it as a parameter so tests can supply an in-memory profile.

type Package

type Package struct {
	Path          string
	HasStatements bool
	TestMains     []string // the test files that declare a TestMain
	Constraints   []string // a message for each build constraint of a Go file
}

Package is a package of the module, as `go list ./...` would list it: its import path, and whether its non-test Go files hold any statement. A package with statements must appear in the cover profile with a statement count above zero: a test binary whose TestMain exits 0 before it runs, or a package the profile was written without, must not make the package vanish from the count.

type Packages

type Packages func() ([]Package, error)

Packages lists the packages of the module. Run takes it as a parameter so that tests can supply a fixed list.

func OSPackages

func OSPackages(root string) Packages

OSPackages lists the packages of the module rooted at root (the directory of its go.mod) the way `go list ./...` does, without running it: every directory with Go files for this platform, except those whose name begins with "." or "_", testdata directories, and nested modules. A directory with only test files is a package without statements.

type Result

type Result struct {
	Covered int
	Total   int
}

Result is the statement count of a cover profile.

func Parse

func Parse(r io.Reader) (Result, error)

Parse reads a cover profile. A block listed more than once (for example by several test binaries) counts once, and counts as covered if any listing covered it.

func ParseByPackage

func ParseByPackage(r io.Reader) (Result, map[string]int, error)

ParseByPackage is Parse that also returns the number of statements the profile holds for each package, named by import path (the directory of a block's file).

func (Result) Complete

func (r Result) Complete() bool

Complete reports whether every statement is covered. An empty profile is not complete: a profile with no statements means the tests did not run.

Jump to

Keyboard shortcuts

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