gocov

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package gocov collects Go coverage by running `go test -coverprofile` in each detected module and parsing the resulting cover profile directly.

No external conversion tool is required: the profile's own `mode:` header and `file:startLine.startCol,endLine.endCol numStmts count` records carry everything the normalized model needs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseProfile

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

ParseProfile reads a Go cover profile and returns, per file path as written in the profile, the hit count of every source line the profile references.

Blocks are expanded across their line range, and a line covered by several blocks keeps the highest count — with `-covermode=count` overlapping blocks are possible, and a line is covered when any statement on it executed.

func ResolveProfilePath

func ResolveProfilePath(profilePath, modulePath string) (string, bool)

ResolveProfilePath converts a path as written in a cover profile into a slash-separated path relative to the module directory.

Profile paths are import paths, so the module path prefix is stripped. ok is false for entries that do not belong to this module, which happens when a profile is produced with -coverpkg or when Go reports a dependency.

Types

type Options

type Options struct {
	// Root is the absolute scan root, used to make reported paths relative.
	Root string
	// WorkDir receives the intermediate .out profile.
	WorkDir string
	// Printer receives progress and diagnostics.
	Printer *ui.Printer
}

Options configures a collection run.

type Result

type Result struct {
	Dir        string
	Rel        string
	ModulePath string
	Files      []model.FileCoverage
	Warnings   []string
	Command    string
	ExitCode   int
	Output     string
	Err        error
}

Result is the outcome for one Go module. A Result is always returned, even when the module failed: a failing `go test` still usually writes a partial profile, and cover100 reports what it can rather than discarding the module.

func Run

func Run(ctx context.Context, p detect.Project, opts Options, index int) *Result

Run executes the module's tests with coverage and parses the profile.

Jump to

Keyboard shortcuts

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