]> Cypherpunks repositories - gostls13.git/commitdiff
testing: print late arriving log line in panic
authorJosh Bleecher Snyder <josharian@gmail.com>
Thu, 14 Jan 2021 22:38:55 +0000 (14:38 -0800)
committerJosh Bleecher Snyder <josharian@gmail.com>
Wed, 24 Feb 2021 16:38:56 +0000 (16:38 +0000)
When you log after a test has completed,
the testing package panics.

Print the logged line as part of that panic,
to aid in debugging.

Change-Id: I3d6689d1eed57c03e300afe37db0c15b2f4acda4
Reviewed-on: https://go-review.googlesource.com/c/go/+/283972
Trust: Josh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/testing/sub_test.go
src/testing/testing.go

index 5b226f85ad198d4280e322cced16157e8191c708..6c7d83aac2c036af89e65de2a1f35f44243f52a7 100644 (file)
@@ -822,7 +822,7 @@ func TestLogAfterComplete(t *T) {
                                                c2 <- fmt.Sprintf("subtest panic with unexpected value %v", p)
                                                return
                                        }
-                                       const want = "Log in goroutine after TestLateLog has completed"
+                                       const want = "Log in goroutine after TestLateLog has completed: log after test"
                                        if !strings.Contains(s, want) {
                                                c2 <- fmt.Sprintf("subtest panic %q does not contain %q", s, want)
                                        }
index 80354d5ce8390735d7409db722acc0a4079397c4..466dd96981acca75264e559ce79a617fc813415e 100644 (file)
@@ -762,7 +762,7 @@ func (c *common) logDepth(s string, depth int) {
                                return
                        }
                }
-               panic("Log in goroutine after " + c.name + " has completed")
+               panic("Log in goroutine after " + c.name + " has completed: " + s)
        } else {
                if c.chatty != nil {
                        if c.bench {