tg.run("get", "-u", ".../")
tg.grepStderrNot("duplicate loads of", "did not remove old packages from cache")
}
+
+func TestFatalInBenchmarkCauseNonZeroExitStatus(t *testing.T) {
+ tg := testgo(t)
+ defer tg.cleanup()
+ tg.runFail("test", "-bench", ".", "./testdata/src/benchfatal")
+ tg.grepBothNot("^ok", "test passed unexpectedly")
+ tg.grepBoth("FAIL.*benchfatal", "test did not run everything")
+}
// An internal function but exported because it is cross-package; part of the implementation
// of the "go test" command.
func RunBenchmarks(matchString func(pat, str string) (bool, error), benchmarks []InternalBenchmark) {
+ runBenchmarksInternal(matchString, benchmarks)
+}
+
+func runBenchmarksInternal(matchString func(pat, str string) (bool, error), benchmarks []InternalBenchmark) bool {
// If no flag was specified, don't run benchmarks.
if len(*matchBenchmarks) == 0 {
- return
+ return true
}
// Collect matching benchmarks and determine longest name.
maxprocs := 1
}
}
}
+ ok := true
for _, Benchmark := range bs {
for _, procs := range cpuList {
runtime.GOMAXPROCS(procs)
fmt.Printf("%-*s\t", maxlen, benchName)
r := b.run()
if b.failed {
+ ok = false
// The output could be very long here, but probably isn't.
// We print it all, regardless, because we don't want to trim the reason
// the benchmark failed.
}
}
}
+ return ok
}
// trimOutput shortens the output from a benchmark, which can be very long.
testOk := RunTests(m.matchString, m.tests)
exampleOk := RunExamples(m.matchString, m.examples)
stopAlarm()
- if !testOk || !exampleOk {
+ if !testOk || !exampleOk || !runBenchmarksInternal(m.matchString, m.benchmarks) {
fmt.Println("FAIL")
after()
return 1
}
fmt.Println("PASS")
- RunBenchmarks(m.matchString, m.benchmarks)
after()
return 0
}