gocov

package module
v0.0.0-...-4af8a47 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2013 License: MIT Imports: 3 Imported by: 0

README

gocov

Coverage testing tool for The Go Programming Language

Build Status

Installation

go get github.com/axw/gocov/gocov

Usage

There are currently three gocov commands: test, report and annotate.

gocov test

Running gocov test <package> will, for the specified package, instrument all imported packages not part of the standard library, and run "go test". Upon completion, coverage data will be emitted in the form of a JSON document.

Controlling instrumentation

By default only the specified package will be instrumented and consequently have coverage information provided for. There are several flags that can change this behaviour.

By running gocov test -deps <package> you direct gocov to recursively instrument package dependencies, in which case coverage information will be provided for all dependencies as well. The coverage information provided is relative only to the tests run in the originally specified package.

e.g. If you run gocov test -deps net/http, then you will see coverage information not just for net/http, but also its dependencies; the output tells you what code in the dependencies is exercised when the net/http tests are run.

If you specify -deps but wish to exclude a specific package from instrumentation, you can pass an additional -exclude flag, e.g. gocov test -deps -exclude comma,separated,packages. If you wish to exclude all packages in GOROOT, then you can use the shortcut -exclude-goroot flag instead.

gocov report

Running gocov report <coverage.json> will generate a textual report from the coverage data output by gocov test. It is assumed that the source code has not changed in between.

Output from gocov test is logged to stdout so users with POSIX compatible terminals can direct the output to gocov report to view a summary of the test coverage, for example: -

gocov test mypackage | gocov report
gocov annotate

Running gocov annotate <coverage.json> <package[.receiver].function> will generate a source listing of the specified function, annotating it with coverage information, such as which lines have been missed.

GoCovGUI: A simple GUI wrapper for the gocov coverage analysis tool.

gocov-html: A simple helper tool for generating HTML output from gocov.

goveralls: Go integration for Coveralls.io continuous code coverage tracking system.

Documentation

Overview

Package gocov is a code coverage analysis tool for Go.

Index

Constants

This section is empty.

Variables

View Source
var Default = &Context{}

Default coverage context.

Functions

This section is empty.

Types

type Context

type Context struct {
	sync.Mutex

	// ObjectList is a sorted list of coverage objects
	// (packages, functions, etc.)
	Objects ObjectList

	// Tracer is used for tracing coverage. If nil, no tracing will occur.
	Tracer Writer

	// TraceFlags alters how coverage is traced.
	TraceFlags TraceFlag
}

Coverage context.

func (*Context) RegisterPackage

func (c *Context) RegisterPackage(name string) *Package

RegisterPackage registers a package for coverage.

type Function

type Function struct {

	// Name is the name of the function. If the function has a receiver, the
	// name will be of the form T.N, where T is the type and N is the name.
	Name string

	// File is the full path to the file in which the function is defined.
	File string

	// Start is the start offset of the function's signature.
	Start int

	// End is the end offset of the function.
	End int

	// statements registered with this function.
	Statements []*Statement

	// number of times the function has been entered.
	Entered int64

	// number of times the function has been left.
	Left int64
	// contains filtered or unexported fields
}

func (*Function) Accumulate

func (f *Function) Accumulate(f2 *Function) error

Accumulate will accumulate the coverage information from the provided Function into this Function.

func (*Function) Enter

func (f *Function) Enter()

Enter informs gocov that the function has been entered.

func (*Function) Leave

func (f *Function) Leave()

Leave informs gocov that the function has been left.

func (*Function) RegisterStatement

func (f *Function) RegisterStatement(startOffset, endOffset int) *Statement

RegisterStatement registers a statement for coverage.

func (*Function) String

func (o *Function) String() string

func (*Function) Uid

func (o *Function) Uid() int

type Object

type Object interface {
	Uid() int
}

Object is an interface implemented by all coverage objects.

type ObjectList

type ObjectList []Object

type Package

type Package struct {

	// Name is the canonical path of the package.
	Name string

	// Functions is a list of functions registered with this package.
	Functions []*Function
	// contains filtered or unexported fields
}

func RegisterPackage

func RegisterPackage(name string) *Package

RegisterPackage registers a package for coverage using the default context.

func (*Package) Accumulate

func (p *Package) Accumulate(p2 *Package) error

Accumulate will accumulate the coverage information from the provided Package into this Package.

func (*Package) RegisterFunction

func (p *Package) RegisterFunction(name, file string, startOffset, endOffset int) *Function

RegisterFunction registers a function for coverage.

func (*Package) String

func (o *Package) String() string

func (*Package) Uid

func (o *Package) Uid() int

type Statement

type Statement struct {

	// Start is the start offset of the statement.
	Start int

	// End is the end offset of the statement.
	End int

	// Reached is the number of times the statement was reached.
	Reached int64
	// contains filtered or unexported fields
}

func (*Statement) Accumulate

func (s *Statement) Accumulate(s2 *Statement) error

Accumulate will accumulate the coverage information from the provided Statement into this Statement.

func (*Statement) At

func (s *Statement) At()

At informs gocov that the statement has been reached.

func (*Statement) String

func (o *Statement) String() string

func (*Statement) Uid

func (o *Statement) Uid() int

type TraceFlag

type TraceFlag int

Flags that affect how results are traced, if a

const (
	// Trace all visits to an object (warning: may increase run time
	// significantly). If this flag is not set, only the first visit
	// to each object will be traced.
	TraceAll TraceFlag = 0x00000001
)

type Writer

type Writer interface {
	Write(p []byte) (n int, err error)
}

Writer is a clone of io.Writer, to avoid the unnecessary package dependency.

Notes

Bugs

  • (unlikely) overflow not handled

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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