Documentation ¶
Index ¶
- func FormatDurationAsSeconds(d time.Duration, precision int) string
- func PrintSummary(out io.Writer, execution *Execution, opts Summary) error
- func RelativePackagePath(pkgpath string) string
- type Action
- type EventFormatter
- type EventHandler
- type Execution
- func (e *Execution) Elapsed() time.Duration
- func (e *Execution) Errors() []string
- func (e *Execution) Failed() []TestCase
- func (e *Execution) Output(pkg, test string) string
- func (e *Execution) OutputLines(pkg, test string) []string
- func (e *Execution) Package(name string) *Package
- func (e *Execution) Packages() []string
- func (e *Execution) Skipped() []TestCase
- func (e *Execution) Total() int
- type Package
- type ScanConfig
- type Summary
- type TestCase
- type TestEvent
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatDurationAsSeconds ¶
FormatDurationAsSeconds formats a time.Duration as a float with an s suffix.
func PrintSummary ¶
PrintSummary of a test Execution. Prints a section for each summary type followed by a DONE line.
func RelativePackagePath ¶ added in v0.4.0
RelativePackagePath attempts to remove a common prefix from a package path. The common prefix is determined either by looking at the GOPATH or reading the package value from go.mod file. If the pkgpath does not match the common prefix it will be returned unmodified. If the pkgpath matches the common prefix exactly then '.' will be returned.
Types ¶
type EventFormatter ¶
EventFormatter is a function which handles an event and returns a string to output for the event.
func NewEventFormatter ¶
func NewEventFormatter(format string) EventFormatter
NewEventFormatter returns a formatter for printing events.
type EventHandler ¶
type EventHandler interface { Event(event TestEvent, execution *Execution) error Err(text string) error }
EventHandler is called by ScanTestOutput for each event and write to stderr.
type Execution ¶
type Execution struct {
// contains filtered or unexported fields
}
Execution of one or more test packages
func NewExecution ¶
func NewExecution() *Execution
NewExecution returns a new Execution and records the current time as the time the test execution started.
func ScanTestOutput ¶
func ScanTestOutput(config ScanConfig) (*Execution, error)
ScanTestOutput reads lines from stdout and stderr, creates an Execution, calls the Handler for each event, and returns the Execution.
func (*Execution) OutputLines ¶
OutputLines returns the full test output for a test as an array of lines.
type Package ¶
type Package struct { // TODO: this could be Total() Total int Failed []TestCase Skipped []TestCase Passed []TestCase // contains filtered or unexported fields }
Package is the set of TestEvents for a single go package
func (Package) Result ¶
Result returns if the package passed, failed, or was skipped because there were no tests.
func (Package) TestMainFailed ¶
TestMainFailed returns true if the package failed, but there were no tests. This may occur if the package init() or TestMain exited non-zero.
type ScanConfig ¶
type ScanConfig struct { Stdout io.Reader Stderr io.Reader Handler EventHandler }
ScanConfig used by ScanTestOutput
type Summary ¶
type Summary int
Summary enumerates the sections which can be printed by PrintSummary
const ( SummarizeNone Summary = 0 SummarizeSkipped Summary = (1 << iota) / 2 SummarizeFailed SummarizeErrors SummarizeOutput SummarizeAll = SummarizeSkipped | SummarizeFailed | SummarizeErrors | SummarizeOutput )
nolint: golint
func NewSummary ¶ added in v0.3.3
NewSummary returns a new Summary from a string value. If the string does not match any known values returns false for the second value.
type TestEvent ¶
type TestEvent struct { // Time encoded as an RFC3339-format string Time time.Time Action Action Package string Test string // Elapsed time in seconds Elapsed float64 // Output of test or benchmark Output string // contains filtered or unexported fields }
TestEvent is a structure output by go tool test2json and go test -json.
func (TestEvent) Bytes ¶
Bytes returns the serialized JSON bytes that were parsed to create the event.
func (TestEvent) ElapsedFormatted ¶
ElapsedFormatted returns Elapsed formatted in the go test format, ex (0.00s).
func (TestEvent) PackageEvent ¶
PackageEvent returns true if the event is a package start or end event