covers

package module
v0.0.0-...-3682ef1 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2023 License: MIT Imports: 10 Imported by: 0

README

Docs

go get jonwillia.ms/covers@latest

Documentation

Overview

Package covers contains a library for programatically asserting that a line of code is covered by a test case via a machine-readable comments. See the tests for simple examples.

BE ADVISED: This package is under construction and the API may change in backwards incompatible ways and without notice.

Index

Constants

View Source
const TagPrefix = "//covers:"

TagPrefix is the prefix for machine-readable comments. For example "//covers:DescriptiveName"

Variables

View Source
var (
	ErrNoCoverage = errors.New("coverage not enabled (-cover)")
	ErrWrongMode  = errors.New("mode not supported for operation")
)

Functions

This section is empty.

Types

type Counters

type Counters struct {
	Snapshot
	// contains filtered or unexported fields
}

Counters represents a mapping of machine-readable "//covers:" tags to coverage counters.

func May

func May(t testing.TB) *Counters

May loads a Counters struct if coverage is enabled. Otherwise the struct is non-functional.

func Must

func Must(t testing.TB) *Counters

Must loads a Counters struct if coverage is enabled. It will fail the test is coverage is unavailable.

func Setup

func Setup(t testing.TB) (*Counters, error)

Setup initializes a Counters object.

func Should

func Should(t testing.TB) *Counters

Should loads a Counters struct if coverage is enabled. Otherwise the struct is non-functional. It will log if coverage was not enabled via command line options.

func (*Counters) NewSnapshot

func (c *Counters) NewSnapshot() Snapshot

NewSnapshot saves the value of coverage counters to a Snapshot.

type Snapshot

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

Snapshot represents the state of the counters at a point in time.

func (*Snapshot) Tag

func (ss *Snapshot) Tag(tag string, f func(delta uint32))

Tag retrieves the change in a counter's value since a snapshot and runs a function on that value. Functions may not be evaluated if we are running in an optional mode (Should or May).

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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