From 7e0d66020c49ef56158346ce18dc3f538393829e Mon Sep 17 00:00:00 2001 From: Marcel van Lohuizen Date: Mon, 4 Apr 2016 18:22:29 +0200 Subject: testing: improve output This introduces a few changes - Skipped benchmarks now print a SKIP line, also if there was no output - The benchmark name is only printed if there the benchmark was not skipped or did not fail in the probe phase. It also fixes a bug of doubling a skip message in chatty mode in absense of a failure. The chatty flag is now passed in the common struct to allow for testing of the printed messages. Fixes #14799 Change-Id: Ia8eb140c2e5bb467e66b8ef20a2f98f5d95415d5 Reviewed-on: https://go-review.googlesource.com/21504 Reviewed-by: Brad Fitzpatrick Run-TryBot: Marcel van Lohuizen TryBot-Result: Gobot Gobot --- src/testing/testing.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/testing/testing.go') diff --git a/src/testing/testing.go b/src/testing/testing.go index f9bb43b618..8e16db321d 100644 --- a/src/testing/testing.go +++ b/src/testing/testing.go @@ -199,6 +199,7 @@ type common struct { mu sync.RWMutex // guards output and failed output []byte // Output generated by test or benchmark. w io.Writer // For flushToParent. + chatty bool // A copy of the chatty flag. failed bool // Test or benchmark has failed. skipped bool // Test of benchmark has been skipped. finished bool @@ -265,7 +266,6 @@ func (c *common) flushToParent(format string, args ...interface{}) { defer p.mu.Unlock() fmt.Fprintf(p.w, format, args...) - fmt.Fprintln(p.w) c.mu.Lock() defer c.mu.Unlock() @@ -562,13 +562,18 @@ func (t *T) Run(name string, f func(t *T)) bool { name: testName, parent: &t.common, level: t.level + 1, + chatty: t.chatty, }, context: t.context, } t.w = indenter{&t.common} - if *chatty { - fmt.Printf("=== RUN %s\n", t.name) + if t.chatty { + // Print directly to root's io.Writer so there is no delay. + root := t.parent + for ; root.parent != nil; root = t.parent { + } + fmt.Fprintf(root.w, "=== RUN %s\n", t.name) } // Instead of reducing the running count of this test before calling the // tRunner and increasing it afterwards, we rely on tRunner keeping the @@ -690,10 +695,10 @@ func (t *T) report() { return } dstr := fmtDuration(t.duration) - format := "--- %s: %s (%s)" + format := "--- %s: %s (%s)\n" if t.Failed() { t.flushToParent(format, "FAIL", t.name, dstr) - } else if *chatty { + } else if t.chatty { if t.Skipped() { t.flushToParent(format, "SKIP", t.name, dstr) } else { @@ -716,6 +721,7 @@ func RunTests(matchString func(pat, str string) (bool, error), tests []InternalT signal: make(chan bool), barrier: make(chan bool), w: os.Stdout, + chatty: *chatty, }, context: ctx, } -- cgit v1.3 From 63cea5ac2b8ed0cf257c7bfe7ed13bdd42373a0c Mon Sep 17 00:00:00 2001 From: Marcel van Lohuizen Date: Wed, 6 Apr 2016 09:59:32 +0200 Subject: testing: fixed bug introduced by CL 21504 This broke T.Run Change-Id: I12c8fe3612f3fa2caa83049c1c7003056daf2b0c Reviewed-on: https://go-review.googlesource.com/21600 Run-TryBot: Marcel van Lohuizen TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/testing/sub_test.go | 24 ++++++++++++++++++++++++ src/testing/testing.go | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) (limited to 'src/testing/testing.go') diff --git a/src/testing/sub_test.go b/src/testing/sub_test.go index e053a3c348..7fe0fffd8f 100644 --- a/src/testing/sub_test.go +++ b/src/testing/sub_test.go @@ -178,6 +178,22 @@ func TestTRun(t *T) { === RUN skipping without message, chatty --- SKIP: skipping without message, chatty (0.00s)`, f: func(t *T) { t.SkipNow() }, + }, { + desc: "chatty with recursion", + ok: true, + chatty: true, + output: ` +=== RUN chatty with recursion +=== RUN chatty with recursion/#00 +=== RUN chatty with recursion/#00/#00 +--- PASS: chatty with recursion (0.00s) + --- PASS: chatty with recursion/#00 (0.00s) + --- PASS: chatty with recursion/#00/#00 (0.00s)`, + f: func(t *T) { + t.Run("", func(t *T) { + t.Run("", func(t *T) {}) + }) + }, }, { desc: "skipping without message, not chatty", ok: true, @@ -435,6 +451,14 @@ func TestBRun(t *T) { --- SKIP: root sub_test.go:: skipping`, f: func(b *B) { b.Skip("skipping") }, + }, { + desc: "chatty with recursion", + chatty: true, + f: func(b *B) { + b.Run("", func(b *B) { + b.Run("", func(b *B) {}) + }) + }, }, { desc: "skipping without message, not chatty", f: func(b *B) { b.SkipNow() }, diff --git a/src/testing/testing.go b/src/testing/testing.go index 8e16db321d..3a7a135a3c 100644 --- a/src/testing/testing.go +++ b/src/testing/testing.go @@ -571,7 +571,7 @@ func (t *T) Run(name string, f func(t *T)) bool { if t.chatty { // Print directly to root's io.Writer so there is no delay. root := t.parent - for ; root.parent != nil; root = t.parent { + for ; root.parent != nil; root = root.parent { } fmt.Fprintf(root.w, "=== RUN %s\n", t.name) } -- cgit v1.3