coverage

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package coverage analyzes Go test coverage to identify which code is tested.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	StartLine int
	StartCol  int
	EndLine   int
	EndCol    int
}

Block holds the start and end coordinates of a section of a source file covered by tests.

type Coverage

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

Coverage is responsible for executing a Go test with coverage via the Run() method, then parsing the result coverage report file.

func New

func New(workdir string, mod gomodule.GoModule, opts ...Option) *Coverage

New instantiates a Coverage element using exec.CommandContext as execContext, actually running the command on the OS.

func NewWithCmd

func NewWithCmd(cmdContext execContext, workdir string, mod gomodule.GoModule, opts ...Option) *Coverage

NewWithCmd instantiates a Coverage element given a custom execContext.

func (*Coverage) Run

func (c *Coverage) Run(ctx context.Context) (Result, error)

Run executes the coverage command and parses the results, returning a *Profile object. Before executing the coverage, it downloads the go modules in a separate step. This is done to avoid that the download phase impacts the execution time which is later used as timeout for the mutant testing execution. The cancellation of ctx stops the running command.

type Option

type Option func(c *Coverage) *Coverage

Option for the Coverage initialization.

type Profile

type Profile map[string][]Block

Profile is implemented as a map holding a slice of Block per each filename.

func (Profile) IsCovered

func (p Profile) IsCovered(pos token.Position) bool

IsCovered checks if the given token.Position is covered by the coverage Profile.

func (Profile) IsDirCovered added in v0.8.0

func (p Profile) IsDirCovered(dir string) bool

IsDirCovered tells if the tests executed a block of a file in the slash-separated directory dir. The files of one directory make one package.

type Result

type Result struct {
	Profile Profile
	Elapsed time.Duration
	Peak    uint64
}

Result contains the Profile generated by the coverage, the time it took to generate the coverage report, and the peak memory in bytes of the largest process of the coverage run.

Jump to

Keyboard shortcuts

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