Version: v0.10.3 Latest Latest

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

Go to latest
Published: May 27, 2022 License: MIT Imports: 11 Imported by: 1




This section is empty.


View Source
var ErrNotParseable = errors.New("failed to parse")

ErrNotParseable indicates the event line was not parseable.


This section is empty.


type Action

type Action string

Action is one of a fixed set of actions describing a single emitted event.

const (
	ActionRun    Action = "run"    // test has started running
	ActionPause  Action = "pause"  // test has been paused
	ActionCont   Action = "cont"   // the test has continued running
	ActionPass   Action = "pass"   // test passed
	ActionBench  Action = "bench"  // benchmark printed log output but did not fail
	ActionFail   Action = "fail"   // test or benchmark failed
	ActionOutput Action = "output" // test printed output
	ActionSkip   Action = "skip"   // test was skipped or the package contained no tests

Prefixed with Action for convenience.

func (Action) String

func (a Action) String() string

type Event

type Event struct {
	// Action can be one of:
	// run, pause, cont, pass, bench, fail, output, skip
	Action Action

	// Portion of the test's output (standard output and standard error merged together)
	Output string

	// Time at which the the event occurred, encodes as an RFC3339-format string.
	// It is conventionally omitted for cached test results.
	Time time.Time

	// The Package field, if present, specifies the package being tested.
	// When the go command runs parallel tests in -json mode, events from
	// different tests are interlaced; the Package field allows readers to separate them.
	Package string

	// The Test field, if present, specifies the test, example, or benchmark
	// function that caused the event. Events for the overall package test do not set Test.
	Test string

	// Elapsed is time elapsed (in seconds) for the specific test or
	// the overall package test that passed or failed.
	Elapsed float64

Event represents a single line of json output from go test with the -json flag.

For more info see, and

func NewEvent

func NewEvent(data []byte) (*Event, error)

NewEvent attempts to decode data into an Event.

func (*Event) Cover

func (e *Event) Cover() (float64, bool)

Cover reports special event case for package coverage: "ok \\t(cached)\tcoverage: 28.8% of statements\n" "ok \\t0.027s\tcoverage: 28.8% of statements\n" "ok \\t0.516s\tcoverage: 34.5% of statements in ./...\n"

func (*Event) DiscardEmptyTestOutput added in v0.10.0

func (e *Event) DiscardEmptyTestOutput() bool

func (*Event) DiscardOutput added in v0.10.0

func (e *Event) DiscardOutput() bool

DiscardOutput reports whether to discard output that belongs to one of the output update actions: === RUN === PAUSE === CONT If output is none one of the above return false.

func (*Event) IsCached

func (e *Event) IsCached() bool

IsCached reports special event case for cached packages: "ok \\t(cached)\n" "ok \\t(cached)\tcoverage: 28.8% of statements\n"

func (*Event) IsPanic added in v0.4.0

func (e *Event) IsPanic() bool

IsPanic indicates a panic event has been detected.

func (*Event) IsRace added in v0.7.0

func (e *Event) IsRace() bool

IsRace indicates a race event has been detected.

func (*Event) LastLine added in v0.4.0

func (e *Event) LastLine() bool

LastLine reports whether the event is the final emitted output line summarizing the package run.

ok 0.583s {Time:2018-10-14 11:45:03.489687 -0400 EDT Action:pass Output: Test: Elapsed:0.584}

FAIL 0.534s {Time:2018-10-14 11:45:23.916729 -0400 EDT Action:fail Output: Test: Elapsed:0.53}

func (*Event) NoTestFiles added in v0.3.0

func (e *Event) NoTestFiles() bool

NoTestFiles reports special event case for packages containing no test files: "? \tpackage\t[no test files]\n"

func (*Event) NoTestsToRun added in v0.2.0

func (e *Event) NoTestsToRun() bool

NoTestsToRun reports special event case for no tests to run: "ok \\t4.543s [no tests to run]\n"

func (*Event) NoTestsWarn added in v0.3.0

func (e *Event) NoTestsWarn() bool

NoTestsWarn whether the event is a test that identifies as: "testing: warning: no tests to run\n"

NOTE: can be found in a package or test event. Must check for non-empty test name in the event.

func (*Event) String added in v0.10.0

func (e *Event) String() string

type GoTestSummary added in v0.10.0

type GoTestSummary struct {
	Packages map[string]*Package

func Process added in v0.4.0

func Process(r io.Reader, optionsFunc ...OptionsFunc) (*GoTestSummary, error)

Process is the entry point to parse. It consumes a reader and parses go test output in JSON format until EOF.

Note, Process will attempt to parse up to 50 lines before returning an error.

func (*GoTestSummary) AddEvent added in v0.10.0

func (s *GoTestSummary) AddEvent(e *Event)

func (*GoTestSummary) AddRawEvent added in v0.10.0

func (s *GoTestSummary) AddRawEvent(str string)

func (*GoTestSummary) ExitCode added in v0.10.0

func (s *GoTestSummary) ExitCode() int

func (*GoTestSummary) GetSortedPackages added in v0.10.0

func (s *GoTestSummary) GetSortedPackages() []*Package

type OptionsFunc added in v0.10.0

type OptionsFunc func(o *options)

func WithDebug added in v0.10.0

func WithDebug() OptionsFunc

func WithFollowOutput added in v0.10.0

func WithFollowOutput(b bool) OptionsFunc

func WithWriter added in v0.10.0

func WithWriter(w io.Writer) OptionsFunc

type Package

type Package struct {
	Summary *Event
	Tests   []*Test

	// NoTestFiles indicates whether the package contains tests: [no test files]
	// This only occurs at the package level
	NoTestFiles bool

	// NoTests indicates a package contains one or more files with no tests. This doesn't
	// necessarily mean the file is empty or that the package doesn't have any tests.
	// Unfortunately go test marks the package summary with [no tests to run].
	NoTests bool
	// NoTestSlice holds events that contain "testing: warning: no tests to run" and
	// a non-empty test name.
	NoTestSlice []*Event

	// Cached indicates whether the test result was obtained from the cache.
	Cached bool

	// Cover reports whether the package contains coverage (go test run with -cover)
	Cover    bool
	Coverage float64

	// HasPanic marks the entire package as panicked. Game over.
	HasPanic bool
	// Once a package has been marked HasPanic all subsequent events are added to PanicEvents.
	PanicEvents []*Event

	// HasDataRace marks the entire package as having a data race.
	HasDataRace bool
	// DataRaceTests captures an individual test names as having a data race.
	DataRaceTests []string

	// HasFailedBuildOrSetup marks the package as having a failed build or setup.
	// Example: [build failed] or [setup failed]
	HasFailedBuildOrSetup bool

Package is the representation of a single package being tested. The summary field is an event that contains all relevant information about the package, namely Package (name), Elapsed and Action (big pass or fail).

func (*Package) AddEvent

func (p *Package) AddEvent(event *Event)

AddEvent adds the event to a test based on test name.

func (*Package) GetTest added in v0.7.0

func (p *Package) GetTest(name string) *Test

GetTest retuns a test based on given name, if no test is found return nil

func (*Package) TestsByAction

func (p *Package) TestsByAction(action Action) []*Test

TestsByAction returns all tests that identify as one of the following actions: pass, skip or fail.

An empty slice if returned if there are no tests.

type Test

type Test struct {
	Name    string
	Package string
	Events  []*Event

Test represents a single, unique, package test.

func (*Test) Elapsed

func (t *Test) Elapsed() float64

Elapsed indicates how long a given test ran (in seconds), by scanning for the largest elapsed value from all events.

func (*Test) SortEvents added in v0.4.0

func (t *Test) SortEvents()

SortEvents sorts test events by elapsed time in ascending order, i.e., oldest to newest.

func (*Test) Status

func (t *Test) Status() Action

Status reports the outcome of the test represented as a single Action: pass, fail or skip.

Jump to

Keyboard shortcuts

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