covergate

package
v0.1.0 Latest Latest
Warning

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

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

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

View Source
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

func ModulePackages(fsys fs.FS) ([]string, error)

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

func TestMains(fsys fs.FS) ([]string, error)

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

type Block struct {
	Location   string
	Statements int
	Hit        bool
}

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

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

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

func (p Profile) Complete() bool

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

func (p Profile) Missing(packages []string) []string

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%.

func (Profile) Totals

func (p Profile) Totals() (covered, total int)

Totals returns the number of covered and of all statements.

func (Profile) Uncovered

func (p Profile) Uncovered() []Block

Uncovered returns the blocks that were never executed, in profile order.

Jump to

Keyboard shortcuts

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