coverage

package
v0.2.4 Latest Latest
Warning

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

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

Documentation

Overview

Package coverage parses a test-coverage report (lcov, Cobertura XML, or JaCoCo XML) into per-file, per-line coverage. The format is auto-detected from the content. Read-only, size-bounded; returns the aggregated measure.CoverageReport plus the raw line map so a caller can compute new-code coverage (changed lines that are covered).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LineCoverage

type LineCoverage map[string]map[int]bool

LineCoverage maps a file path to (line number -> covered). A line present here is an executable line; absent lines are not counted.

func Parse

Parse reads a coverage report file, auto-detects its format, and returns the aggregated report plus the per-line map.

func ParseBytes

func ParseBytes(data []byte) (measure.CoverageReport, LineCoverage, error)

ParseBytes parses coverage data whose format is auto-detected: XML with a <coverage> root is Cobertura, XML with a <report> root is JaCoCo, a `mode:` header is a Go -coverprofile, otherwise the data is treated as lcov.

func ParseBytesWithOptions added in v0.2.0

func ParseBytesWithOptions(data []byte, opts Options) (measure.CoverageReport, LineCoverage, error)

ParseBytesWithOptions is ParseBytes with format options.

func ParseWithOptions added in v0.2.0

func ParseWithOptions(path string, opts Options) (measure.CoverageReport, LineCoverage, error)

ParseWithOptions is Parse with format options.

func (LineCoverage) NewCodePercent

func (lc LineCoverage) NewCodePercent(changed map[string]map[int]bool) (pct float64, ok bool)

NewCodePercent is coverage on new code. The measurement lives on the domain type so the server-side measures can compute it without importing this package; this is the same function.

type Options added in v0.2.0

type Options struct {
	// GoModulePath is the `module` directive of the scanned tree. A Go -coverprofile names files by
	// import path (module/pkg/file.go); with the module path known, that prefix is stripped so the
	// result keys on repo-relative paths like every other format. Empty leaves Go paths untouched.
	GoModulePath string
}

Options tunes parsing for formats whose file paths are not repo-relative on their own.

Jump to

Keyboard shortcuts

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