coverlib

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Export

func Export(p *Profiles, format Format, writer io.Writer) error

Export coverage data to the given format.

func ExportCodecovJson

func ExportCodecovJson(p *Profiles, writer io.Writer) error

ExportCodecovJson exports profile data to the Codecov custom coverage JSON format (https://docs.codecov.com/docs/codecov-custom-coverage-format).

Sample output (with added comments):

{
  "coverage": {
    "filename": {
      "1": 0,      # line 1 missed
      "2": 1,      # line 2 hit once
      "7": 5       # line 7 hit 5 times
    }
  }
}

func ExportLCOV

func ExportLCOV(p *Profiles, writer io.Writer) error

ExportLCOV exports profile data to the LCOV format (see https://ltp.sourceforge.net/coverage/lcov/geninfo.1.php).

Types

type Format

type Format int
const (
	FormatUnset Format = iota
	FormatGoCover
	FormatLCOV
	FormatCodecovJSON
)

func FormatFromFilename

func FormatFromFilename(filename string) (Format, error)

FormatFromFilename determines the format from the extension of the filename. Supported extensions are: .gocov, .lcov, .json

type LineCounts

type LineCounts struct {
	// contains filtered or unexported fields
}

LineCounts stores the hit counts for a file.

func (*LineCounts) CopyFrom

func (lc *LineCounts) CopyFrom(other *LineCounts)

CopyFrom copies the given counts.

func (*LineCounts) ForEach

func (lc *LineCounts) ForEach(fn func(lineIdx, hitCount int))

ForEach runs the given function for each line that has a hit count (in increasing lineIdx order).

func (*LineCounts) MergeWith

func (lc *LineCounts) MergeWith(other *LineCounts)

MergeWith merges in the given line counts.

For any given line, the resulting hit count is the sum between the two hit counts.

func (*LineCounts) Reset

func (lc *LineCounts) Reset()

Reset deletes all counts.

func (*LineCounts) Set

func (lc *LineCounts) Set(lineIdx, hitCount int)

Set the hit count for a line. If the line already has a hit count, the larger value is used.

func (*LineCounts) String

func (lc *LineCounts) String() string

func (*LineCounts) StringWithSeparator

func (lc *LineCounts) StringWithSeparator(sep string) string

StringWithSeparator generates a string representation showing groups of lines with the same hit count, separated by the given separator.

type Profiles

type Profiles struct {
	// contains filtered or unexported fields
}

Profiles stores LineCounts for a collection of files.

func Import

func Import(format Format, reader io.Reader) (*Profiles, error)

Import coverage data from the given format.

func ImportGoCover

func ImportGoCover(reader io.Reader) (*Profiles, error)

ImportGoCover imports go cover profile data.

func ImportLCOV

func ImportLCOV(reader io.Reader) (*Profiles, error)

ImportLCOV imports profile data from LCOV format (see https://ltp.sourceforge.net/coverage/lcov/geninfo.1.php).

func (*Profiles) Files

func (p *Profiles) Files() []string

Files returns all filenames in the collection (sorted).

func (*Profiles) LineCounts

func (p *Profiles) LineCounts(filename string) *LineCounts

LineCounts returns the LineCounts for the given file, adding the file to the collection if necessary.

func (*Profiles) MergeWith

func (p *Profiles) MergeWith(other *Profiles)

MergeWith merges in the given profiles.

For any given line, the resulting hit count is the sum between the hit counts in the two profiles.

func (*Profiles) RenameFiles

func (p *Profiles) RenameFiles(renameFn func(filenameBefore string) string)

RenameFiles changes the names of the files in the profile.

func (*Profiles) String

func (p *Profiles) String() string

Jump to

Keyboard shortcuts

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