Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoProfiles is returned by [Parser.Parse] if profile contains no data. ErrNoProfiles = errors.New("cover profile contains no coverage data") // ErrNoPackages is returned by [Parser.Parse] if profile contains no package data. ErrNoPackages = errors.New("cover profile contains no package coverage data") )
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*Parser)
Option configures a Parser.
func WithGoBinPath ¶
WithGoBinPath configures Parser to use path as go binary for commands.
By default, `go` is used.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser parses Go test coverage profile data.
func (*Parser) Parse ¶
Parse test coverage data from Go coverprofile data.
Parses the content of a file created by the `go test -coverprofile=...` command and returns a report with coverage data and contents of tested files.
Uses pkg.go.dev/golang.org/x/tools/cover under the hood to parse the coverprofile data.
type Profile ¶
type Profile struct { FileName string `json:"filename"` // Name of file. Package string `json:"package"` // Package where file belongs. Path string `json:"path"` // Absolute path to file. Content []byte `json:"content"` // Content of file at time of testing. Size int `json:"size"` // File size. Coverage float64 `json:"coverage"` // Coverage percentage of file. LineCount int `json:"lineCount"` // Number of lines in file. Boundaries []ProfileBoundary `json:"boundaries"` // Boundaries map coverage of the content. }
Profile of a single file in coverage report.
type ProfileBoundary ¶
type ProfileBoundary struct { Offset int `json:"offset"` // Location as a byte offset in the content. Start bool `json:"start"` // Is this the start of a block? Count int `json:"count"` // Amount of times block was invoked in tests. Norm float64 `json:"norm"` // Coverage normalized to [0..1]. Index int `json:"index"` // Order in content. }
ProfileBoundary represents the position in a source file of the beginning and end of a block as reported by the coverage profile.
User interfaces can use this to mark coverage of a file, e.g. by wrapping file content in HTML tags between start and end offsets.