gocov

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2024 License: BSD-3-Clause Imports: 18 Imported by: 1

README

gocov

Library to read go coverage data programmatically

Why?

Because I want coverage information at runtime. go API's are closed and the tools repo has not been updated with the new coverage data structures.

How?

Credit to the go team, I reused most of their code (internal/coverage) and defined wrapper data structures.

Problems?

Tightly coupled with the encoding format of the Coverage information. i.e. The go compiler version.

TODO

  • Need to add a version check
  • Merge and diff CoverageData

Documentation

Index

Constants

View Source
const (
	CtrModeInvalid  counterMode = iota
	CtrModeSet                  // "set" mode
	CtrModeCount                // "count" mode
	CtrModeAtomic               // "atomic" mode
	CtrModeRegOnly              // registration-only pseudo-mode
	CtrModeTestMain             // testmain pseudo-mode
)

Variables

This section is empty.

Functions

func DiffLines

func DiffLines(one, two *CoverageData) int

Return the number of new lines covered by the second argument over the first

func ParseCounterMode

func ParseCounterMode(mode string) counterMode

Types

type CounterGranularity

type CounterGranularity uint8

CounterGranularity tracks the granularity of the coverage counters being used in a given coverage-instrumented program.

const (
	CtrGranularityInvalid CounterGranularity = iota
	CtrGranularityPerBlock
	CtrGranularityPerFunc
)

func (CounterGranularity) String

func (cm CounterGranularity) String() string

type Coverage

type Coverage struct {
	Data *CoverageData
	// contains filtered or unexported fields
}

func GetCoverage

func GetCoverage(c CoverageConfig) (*Coverage, error)

func (*Coverage) GetCoveredLines added in v0.2.1

func (c *Coverage) GetCoveredLines() int

func (*Coverage) GetPercent

func (c *Coverage) GetPercent() float64

func (*Coverage) GetProfiles

func (c *Coverage) GetProfiles() []cover.Profile

func (*Coverage) Reset added in v0.2.2

func (c *Coverage) Reset() error

type CoverageConfig

type CoverageConfig struct {
	UseDir    string
	MatchPkgs []string
}

type CoverageData

type CoverageData struct {
	PodData map[string]*PodData
}

func ReadDir

func ReadDir(dir string, matchPkgs []string) (*CoverageData, error)

func ReadFromBuffer

func ReadFromBuffer(meta, counters *bytes.Buffer, matchPkgs []string) (*CoverageData, error)

func (*CoverageData) Merge added in v0.2.0

func (cur *CoverageData) Merge(other *CoverageData)

type Func

type Func struct {
	Name    string
	SrcFile string
	Units   []*FuncUnit
}

type FuncUnit

type FuncUnit struct {
	StLine, StCol uint32
	EnLine, EnCol uint32
	NxStmts       uint32
	Count         uint32
}

type Package

type Package struct {
	ID         uint32
	Name       string
	ImportPath string
	ModulePath string
	NumFuncs   uint32
	Funcs      map[uint32]*Func
}

type PodData

type PodData struct {
	CounterGranularity CounterGranularity
	CounterMode        counterMode
	// Number of functions in each package
	Packages map[uint32]*Package
}

Directories

Path Synopsis
Package bio implements common I/O abstractions used within the Go toolchain.
Package bio implements common I/O abstractions used within the Go toolchain.

Jump to

Keyboard shortcuts

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