Documentation ¶
Index ¶
- Variables
- func SortByCoverage(packages []*Package) sort.Interface
- func SortByElapsed(packages []*Package) sort.Interface
- func SortByPackageName(packages []*Package) sort.Interface
- type Action
- type Event
- func (e *Event) Cover() (float64, bool)
- func (e *Event) DiscardEmptyTestOutput() bool
- func (e *Event) DiscardOutput() bool
- func (e *Event) IsCached() bool
- func (e *Event) IsPanic() bool
- func (e *Event) IsRace() bool
- func (e *Event) LastLine() bool
- func (e *Event) NoTestFiles() bool
- func (e *Event) NoTestsToRun() bool
- func (e *Event) NoTestsWarn() bool
- func (e *Event) String() string
- type GoTestSummary
- type OptionsFunc
- type Package
- type PackageSlice
- type PackageSorter
- type Test
Constants ¶
This section is empty.
Variables ¶
var ErrNotParsable = errors.New("failed to parse")
ErrNotParsable indicates the event line was not parsable.
Functions ¶
func SortByCoverage ¶ added in v0.11.0
SortByCoverage sorts packages in descending order of code coverage.
func SortByElapsed ¶ added in v0.11.0
SortByElapsed sorts packages in descending order of elapsed time per package.
func SortByPackageName ¶ added in v0.11.0
SortByPackageName sorts packages in ascending alphabetical order.
Types ¶
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 // Added in go1.20 to denote the beginning of each test program's execution. ActionStart Action = "start" // the start at the beginning of each test program's execution )
Prefixed with Action for convenience.
type Event ¶
type Event struct { // Action can be one of: run, pause, cont, pass, bench, fail, output, skip, start // // Note, start is only available in go1.20 and above. Action Action // Portion of the test's output (standard output and standard error merged together) Output string // Time at which 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, https://golang.org/cmd/test2json and https://github.com/golang/go/blob/master/src/cmd/internal/test2json/test2json.go
func (*Event) Cover ¶
Cover reports special event case for package coverage: "ok \tgithub.com/mfridman/srfax\t(cached)\tcoverage: 28.8% of statements\n" "ok \tgithub.com/mfridman/srfax\t0.027s\tcoverage: 28.8% of statements\n" "ok \tgithub.com/mfridman/tparse/tests\t0.516s\tcoverage: 34.5% of statements in ./...\n"
func (*Event) DiscardEmptyTestOutput ¶ added in v0.10.0
func (*Event) DiscardOutput ¶ added in v0.10.0
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 ¶
IsCached reports special event case for cached packages: "ok \tgithub.com/mfridman/tparse/tests\t(cached)\n" "ok \tgithub.com/mfridman/srfax\t(cached)\tcoverage: 28.8% of statements\n"
func (*Event) LastLine ¶ added in v0.4.0
LastLine reports whether the event is the final emitted output line summarizing the package run.
ok github.com/astromail/rover/tests 0.583s {Time:2018-10-14 11:45:03.489687 -0400 EDT Action:pass Output: Package:github.com/astromail/rover/tests Test: Elapsed:0.584}
FAIL github.com/astromail/rover/tests 0.534s {Time:2018-10-14 11:45:23.916729 -0400 EDT Action:fail Output: Package:github.com/astromail/rover/tests Test: Elapsed:0.53}
func (*Event) NoTestFiles ¶ added in v0.3.0
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
NoTestsToRun reports special event case for no tests to run: "ok \tgithub.com/some/awesome/module\t4.543s [no tests to run]\n"
func (*Event) NoTestsWarn ¶ added in v0.3.0
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.
type GoTestSummary ¶ added in v0.10.0
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(sorter PackageSorter) []*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 WithProgress ¶ added in v0.13.0
func WithProgress(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 // StartTime is the time the package started running. This is only available // in go1.20 and above. StartTime time.Time // 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) GetTest ¶ added in v0.7.0
GetTest returns a test based on given name, if no test is found return nil
func (*Package) TestsByAction ¶
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 PackageSlice ¶ added in v0.11.0
type PackageSlice []*Package
func (PackageSlice) Len ¶ added in v0.11.0
func (packages PackageSlice) Len() int
func (PackageSlice) Less ¶ added in v0.11.0
func (packages PackageSlice) Less(i, j int) bool
func (PackageSlice) Swap ¶ added in v0.11.0
func (packages PackageSlice) Swap(i, j int)
type PackageSorter ¶ added in v0.11.0
type Test ¶
Test represents a single, unique, package test.
func (*Test) Elapsed ¶
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.