coverage

package
v2.7.6 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CountTests added in v2.6.6

func CountTests(pkgPath string) int

CountTests returns the number of test functions (Test*, Benchmark*, Fuzz*) in pkgPath. Returns 0 on any error or when the package has no tests.

Types

type PerTestProfile added in v2.6.2

type PerTestProfile struct {
	// contains filtered or unexported fields
}

PerTestProfile maps each (module-relative file path, line) to the sorted list of test function names that cover it. Callers look up by absolute file path using CoveringTests; the match is done via suffix so it survives GOPATH/module root variations.

func BuildPerTestProfile added in v2.6.2

func BuildPerTestProfile(pkgPath, modulePath, tmpDir string, timeout uint, workers int, extraTestFlags []string) (*PerTestProfile, error)

func (*PerTestProfile) CoveringTests added in v2.6.2

func (p *PerTestProfile) CoveringTests(absFile string, lineNum int) []string

CoveringTests returns the sorted test names that cover absFile at lineNum. Returns nil when the line is not covered by any individually-run test.

type Profile

type Profile struct {
	// contains filtered or unexported fields
}

Profile holds which source lines are covered by tests.

func ParseProfile

func ParseProfile(path, modulePath string) (*Profile, error)

ParseProfile parses a Go coverage profile (generated by go test -coverprofile) using modulePath to strip the module prefix from each entry, leaving relative paths that can be matched against absolute file paths.

Example: with modulePath="github.com/acme/app", the profile entry "github.com/acme/app/pkg/foo.go:5.1,10.3 2 1" becomes key "pkg/foo.go".

func (*Profile) IsCovered

func (p *Profile) IsCovered(absFile string, line int) bool

IsCovered reports whether the given absolute file path and line number are reached by any test. The match uses the relative path suffix of absFile against the module-relative keys stored in the profile.

Jump to

Keyboard shortcuts

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