Commit 0e92b538 authored by Robert Dinu's avatar Robert Dinu Committed by Rob Pike

testing: fix timing format inconsistency

Fixes #8175.

LGTM=r
R=golang-codereviews, r, gobot
CC=golang-codereviews
https://golang.org/cl/103320043
parent 7dcbf4f3
...@@ -71,7 +71,7 @@ func runExample(eg InternalExample) (ok bool) { ...@@ -71,7 +71,7 @@ func runExample(eg InternalExample) (ok bool) {
// Clean up in a deferred call so we can recover if the example panics. // Clean up in a deferred call so we can recover if the example panics.
defer func() { defer func() {
d := time.Now().Sub(start) dstr := fmtDuration(time.Now().Sub(start))
// Close pipe, restore stdout, get output. // Close pipe, restore stdout, get output.
w.Close() w.Close()
...@@ -84,10 +84,10 @@ func runExample(eg InternalExample) (ok bool) { ...@@ -84,10 +84,10 @@ func runExample(eg InternalExample) (ok bool) {
fail = fmt.Sprintf("got:\n%s\nwant:\n%s\n", g, e) fail = fmt.Sprintf("got:\n%s\nwant:\n%s\n", g, e)
} }
if fail != "" || err != nil { if fail != "" || err != nil {
fmt.Printf("--- FAIL: %s (%v)\n%s", eg.Name, d, fail) fmt.Printf("--- FAIL: %s (%s)\n%s", eg.Name, dstr, fail)
ok = false ok = false
} else if *chatty { } else if *chatty {
fmt.Printf("--- PASS: %s (%v)\n", eg.Name, d) fmt.Printf("--- PASS: %s (%s)\n", eg.Name, dstr)
} }
if err != nil { if err != nil {
panic(err) panic(err)
......
...@@ -223,6 +223,11 @@ func decorate(s string) string { ...@@ -223,6 +223,11 @@ func decorate(s string) string {
return buf.String() return buf.String()
} }
// fmtDuration returns a string representing d in the form "87.00s".
func fmtDuration(d time.Duration) string {
return fmt.Sprintf("%.2fs", d.Seconds())
}
// TB is the interface common to T and B. // TB is the interface common to T and B.
type TB interface { type TB interface {
Error(args ...interface{}) Error(args ...interface{})
...@@ -446,15 +451,15 @@ func Main(matchString func(pat, str string) (bool, error), tests []InternalTest, ...@@ -446,15 +451,15 @@ func Main(matchString func(pat, str string) (bool, error), tests []InternalTest,
} }
func (t *T) report() { func (t *T) report() {
tstr := fmt.Sprintf("(%.2f seconds)", t.duration.Seconds()) dstr := fmtDuration(t.duration)
format := "--- %s: %s %s\n%s" format := "--- %s: %s (%s)\n%s"
if t.Failed() { if t.Failed() {
fmt.Printf(format, "FAIL", t.name, tstr, t.output) fmt.Printf(format, "FAIL", t.name, dstr, t.output)
} else if *chatty { } else if *chatty {
if t.Skipped() { if t.Skipped() {
fmt.Printf(format, "SKIP", t.name, tstr, t.output) fmt.Printf(format, "SKIP", t.name, dstr, t.output)
} else { } else {
fmt.Printf(format, "PASS", t.name, tstr, t.output) fmt.Printf(format, "PASS", t.name, dstr, t.output)
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment