Imports #
"cmp"
"fmt"
"internal/coverage"
"internal/coverage/cmerge"
"io"
"maps"
"slices"
"sort"
"strings"
"text/tabwriter"
"cmp"
"fmt"
"internal/coverage"
"internal/coverage/cmerge"
"io"
"maps"
"slices"
"sort"
"strings"
"text/tabwriter"
type Formatter struct {
pm map[string]*pstate
pkg string
p *pstate
cm coverage.CounterMode
}
extcu encapsulates a coverable unit within some function.
type extcu struct {
fnfid uint32
coverage.CoverableUnit
}
fnfile is a function-name/file-name tuple.
type fnfile struct {
file string
fname string
lit bool
}
pstate records package-level coverage data state: - a table of functions (file/fname/literal) - a map recording the index/ID of each func encountered so far - a table storing execution count for the coverable units in each func
type pstate struct {
funcs []fnfile
funcTable map[fnfile]uint32
unitTable map[extcu]uint32
}
AddUnit passes info on a single coverable unit (file, funcname, literal flag, range of lines, and counter value) to the formatter. Counter values will be accumulated where appropriate.
func (fm *Formatter) AddUnit(file string, fname string, isfnlit bool, unit coverage.CoverableUnit, count uint32)
EmitFuncs writes out a function-level summary to the writer 'w'. A note on handling function literals: although we collect coverage data for unnamed literals, it probably does not make sense to include them in the function summary since there isn't any good way to name them (this is also consistent with the legacy cmd/cover implementation). We do want to include their counts in the overall summary however.
func (fm *Formatter) EmitFuncs(w io.Writer) error
EmitPercent writes out a "percentage covered" string to the writer 'w', selecting the set of packages in 'pkgs' and suffixing the printed string with 'inpkgs'.
func (fm *Formatter) EmitPercent(w io.Writer, pkgs []string, inpkgs string, noteEmpty bool, aggregate bool) error
EmitTextual writes the accumulated coverage data for 'pkgs' in the legacy cmd/cover text format to the writer 'w'; if pkgs is empty, text output is emitted for all packages recorded. We sort the data items by importpath, source file, and line number before emitting (this sorting is not explicitly mandated by the format, but seems like a good idea for repeatable/deterministic dumps).
func (fm *Formatter) EmitTextual(pkgs []string, w io.Writer) error
func NewFormatter(cm coverage.CounterMode) *Formatter
SetPackage tells the formatter that we're about to visit the coverage data for the package with the specified import path. Note that it's OK to call SetPackage more than once with the same import path; counter data values will be accumulated.
func (fm *Formatter) SetPackage(importpath string)
sortUnits sorts a slice of extcu objects in a package according to source position information (e.g. file and line). Note that we don't include function name as part of the sorting criteria, the thinking being that is better to provide things in the original source order.
func (p *pstate) sortUnits(units []extcu)
Generated with Arrow