bincover

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2020 License: MIT Imports: 11 Imported by: 5

README

bincover

Build Status codecov GoDoc

Easily measure code coverage of Golang binaries

Check out this blog post to see an example of Bincover is used, and how it works under the hood.

Documentation

Overview

Package bincover provides an easy way to measure code coverage of Golang binaries. See examples/ to see how bincover is used to measure coverage of a simple Go application.

Index

Constants

This section is empty.

Variables

View Source
var (
	ExitCode = 0
)

Functions

func RunTest

func RunTest(f func())

RunTest runs function f (usually main), with arguments specified by the flag "args-file", a file of newline-separated args. When f runs to completion (success or failure), RunTest prints (newline-separated): 1. f's output, 2. startOfMetadataMarker 3. a testMetadata struct 4. endOfMetadataMarker

Otherwise, if an unexpected error is encountered during execution, RunTest panics.

Types

type CoverageCollector

type CoverageCollector struct {
	MergedCoverageFilename string
	CollectCoverage        bool
	// contains filtered or unexported fields
}

func NewCoverageCollector

func NewCoverageCollector(mergedCoverageFilename string, collectCoverage bool) *CoverageCollector

NewCoverageCollector initializes a CoverageCollector with the specified merged coverage filename. CollectCoverage can be set to true to collect coverage, or set to false to skip coverage collection. This is provided in order to enable reuse of CoverageCollector for tests where coverage measurement is not needed.

func (*CoverageCollector) RunBinary

func (c *CoverageCollector) RunBinary(binPath string, mainTestName string, env []string, args []string, options ...CoverageCollectorOption) (output string, exitCode int, err error)

RunBinary runs the instrumented binary at binPath with env environment variables, executing only the test with mainTestName with the specified args.

func (*CoverageCollector) Setup

func (c *CoverageCollector) Setup() error

func (*CoverageCollector) TearDown

func (c *CoverageCollector) TearDown() error

TearDown merges the coverage profiles collecting from repeated runs of RunBinary. It must be called at the teardown stage of the test suite, otherwise no merged coverage profile will be created.

type CoverageCollectorOption added in v0.2.0

type CoverageCollectorOption func(collector *CoverageCollector)

func PostExec added in v0.2.0

func PostExec(postCmdFuncs ...PostCmdFunc) CoverageCollectorOption

func PreExec added in v0.2.0

func PreExec(preCmdFuncs ...PreCmdFunc) CoverageCollectorOption

type PostCmdFunc added in v0.2.0

type PostCmdFunc func(cmd *exec.Cmd, output string, err error) error

type PreCmdFunc added in v0.2.0

type PreCmdFunc func(cmd *exec.Cmd) error

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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