coverage

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Report

func Report(path string) error

Report reports the coverage of the current binary to the given file.

This operates by calling a private function in the testing package, so it's not guaranteed to continue working in the future.

Types

type Bucket

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

Bucket is a collection of coverage profiles obtained from calling an external program.

We use this in conjunction with the Report function to get coverage data from a copy of tmux-fastcopy spawned by tmux.

Roughly, the ingtegration test uses the usual TestMain hijacking method to allow control of the binary spawned by tmux. When running in coverage mode,

  • the test sets up a bucket to place coverage data in, and communicates the path to this bucket to the spawned binary with an environment variable
  • the spanwed binary, if this environment variable is set, generates a coverage report into this directory using coverage.Report
  • afterwards, the test uses Bucket.Finalize to merge coverage data from the spawned binary back into the current process

This is inspired by go-internal/testscript1, but instead of replaying the full test machinery, we just invoke or modify a couple private functions/variables in the testing packge to make this work.

func NewBucket

func NewBucket(coverMode string) (*Bucket, error)

NewBucket builds a new coverage bucket with the given coverage mode. Returns a no-op bucket if we're not running with coverage.

This should only be called from inside a test, or *after* flag.Parse in TestMain.

func (*Bucket) Dir

func (b *Bucket) Dir() string

Dir reports the directory inside which coverage data should be placed.

Coverage-instrumented binaries should use coverage.Report to place their coverage data inside this directory.

func (*Bucket) Finalize

func (b *Bucket) Finalize() (err error)

Finalize cleans up temporary resources allocated by this bucket and merges coverage data from the external coverage-instrumented binaries back into this process.

Jump to

Keyboard shortcuts

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