Skip to content

Commit

Permalink
testing: print late arriving log line in panic
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
josharian committed Feb 24, 2021
1 parent ae1fa08 commit 27684ea
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/testing/sub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion src/testing/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 27684ea

Please sign in to comment.