testing: print test results to standard output

Errors in the code under test go to standard output.
Errors in testing or its usage go to standard error.

R=r
CC=golang-dev
https://golang.org/cl/5374090
This commit is contained in:
Russ Cox 2011-11-15 13:09:19 -05:00
parent 3db596113d
commit a3fb1aec6b
3 changed files with 24 additions and 26 deletions

View file

@ -201,10 +201,10 @@ func Main(matchString func(pat, str string) (bool, error), tests []InternalTest,
testOk := RunTests(matchString, tests)
exampleOk := RunExamples(examples)
if !testOk || !exampleOk {
fmt.Fprintln(os.Stderr, "FAIL")
fmt.Println("FAIL")
os.Exit(1)
}
fmt.Fprintln(os.Stderr, "PASS")
fmt.Println("PASS")
stopAlarm()
RunBenchmarks(matchString, benchmarks)
after()
@ -214,9 +214,9 @@ func report(t *T) {
tstr := fmt.Sprintf("(%.2f seconds)", float64(t.ns)/1e9)
format := "--- %s: %s %s\n%s"
if t.failed {
fmt.Fprintf(os.Stderr, format, "FAIL", t.name, tstr, t.errors)
fmt.Printf(format, "FAIL", t.name, tstr, t.errors)
} else if *chatty {
fmt.Fprintf(os.Stderr, format, "PASS", t.name, tstr, t.errors)
fmt.Printf(format, "PASS", t.name, tstr, t.errors)
}
}
@ -236,7 +236,7 @@ func RunTests(matchString func(pat, str string) (bool, error), tests []InternalT
for i := 0; i < len(tests); i++ {
matched, err := matchString(*match, tests[i].Name)
if err != nil {
println("invalid regexp for -test.run:", err.Error())
fmt.Fprintf(os.Stderr, "testing: invalid regexp for -test.run: %s\n", err)
os.Exit(1)
}
if !matched {
@ -248,7 +248,7 @@ func RunTests(matchString func(pat, str string) (bool, error), tests []InternalT
}
t := &T{ch: ch, name: testName, startParallel: startParallel}
if *chatty {
println("=== RUN", t.name)
fmt.Printf("=== RUN %s\n", t.name)
}
go tRunner(t, &tests[i])
out := <-t.ch
@ -344,7 +344,7 @@ func parseCpuList() {
for _, val := range strings.Split(*cpuListStr, ",") {
cpu, err := strconv.Atoi(val)
if err != nil || cpu <= 0 {
println("invalid value for -test.cpu")
fmt.Fprintf(os.Stderr, "testing: invalid value %q for -test.cpu", val)
os.Exit(1)
}
cpuList = append(cpuList, cpu)