Documentation
¶
Overview ¶
Package gotest counts the results in go test -json output so that a skipped test never reads as a passed one.
Count reads the test2json stream of one go test run together with the run's exit error. It keeps every test's outcome by name, including the output a skipped test printed, and counts as failures the things a plain pass/fail tally misses: a package that fails with no failing test (a build failure or a panic in TestMain), a test that starts and never finishes (a timeout), output that is not test2json, and a nonzero exit with no failure event at all. Report.Err is nil only if nothing failed and at least one test passed.
Example ¶
package main
import (
"fmt"
"strings"
"github.com/tmc/lib/nvidia/internal/gotest"
)
func main() {
const out = `{"Action":"run","Package":"p","Test":"TestA"}
{"Action":"pass","Package":"p","Test":"TestA"}
{"Action":"run","Package":"p","Test":"TestGPU"}
{"Action":"output","Package":"p","Test":"TestGPU","Output":" no CUDA device\n"}
{"Action":"skip","Package":"p","Test":"TestGPU"}
{"Action":"pass","Package":"p"}`
r, _ := gotest.Count(strings.NewReader(out), nil)
fmt.Printf("passed=%d skipped=%d failed=%d err=%v\n", r.Passed, r.Skipped, r.Failed, r.Err())
for _, t := range r.With(gotest.Skip) {
fmt.Printf("skipped %s: %s", t.Name, strings.TrimSpace(t.Output))
}
}
Output: passed=1 skipped=1 failed=0 err=<nil> skipped TestGPU: no CUDA device
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Report ¶
type Report struct {
Tests []Test // in the order they finished; unfinished ones last
Packages []Package
Passed int // tests that passed
Skipped int // tests that skipped; never counted as passed
// Failed counts failed and unfinished tests plus one for each
// Problem.
Failed int
// Problems are failures not attributed to a test: a package that
// failed with no failing test, output that is not test2json, and a
// nonzero exit with no failure event.
Problems []string
}
A Report is the outcome of one go test run.
func Count ¶
Count reads go test -json output from r. runErr is the error go test exited with, if any. Count returns an error only if r cannot be read.