diff options
| author | suntala <artichaut2023@gmail.com> | 2025-05-12 19:23:41 +0000 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2025-05-13 08:06:08 -0700 |
| commit | 8d189f188e225e4919b34c0c097e75dfda255949 (patch) | |
| tree | 0ab80a7bf2f416cc7219e6a071d39b5dd4d0e577 /src/testing/panic_test.go | |
| parent | a2fbb50322e716f75e9c4707afd2de725a95e14b (diff) | |
| download | go-8d189f188e225e4919b34c0c097e75dfda255949.tar.xz | |
testing: add Output
Output is a method on T, B and F. It provides an io.Writer that writes
to the same test output stream as TB.Log. The new output writer is
used to refactor the implementation of Log. It maintains the formatting
provided by Log while making call site information optional.
Additionally, it provides buffering of log messages.
Co-authored-by: Aleks Fazlieva <britishrum@users.noreply.github.com>
Fixes #59928.
Change-Id: I29090b3d4f61f7334388b373ec18750d5637aafa
GitHub-Last-Rev: 18af0e15262494f2074d545a6042b079d62301a2
GitHub-Pull-Request: golang/go#71575
Reviewed-on: https://go-review.googlesource.com/c/go/+/646956
Reviewed-by: Arati <artichaut2023@gmail.com>
Auto-Submit: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Diffstat (limited to 'src/testing/panic_test.go')
| -rw-r--r-- | src/testing/panic_test.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/testing/panic_test.go b/src/testing/panic_test.go index 1c42f9f8dd..fc84175ee6 100644 --- a/src/testing/panic_test.go +++ b/src/testing/panic_test.go @@ -34,6 +34,7 @@ func TestPanic(t *testing.T) { want: ` --- FAIL: TestPanicHelper (N.NNs) panic_test.go:NNN: TestPanicHelper + TestPanicHelper `, }, { desc: "subtest panics", @@ -41,8 +42,10 @@ func TestPanic(t *testing.T) { want: ` --- FAIL: TestPanicHelper (N.NNs) panic_test.go:NNN: TestPanicHelper + TestPanicHelper --- FAIL: TestPanicHelper/1 (N.NNs) panic_test.go:NNN: TestPanicHelper/1 + TestPanicHelper/1 `, }, { desc: "subtest panics with cleanup", @@ -53,8 +56,10 @@ ran middle cleanup 1 ran outer cleanup --- FAIL: TestPanicHelper (N.NNs) panic_test.go:NNN: TestPanicHelper + TestPanicHelper --- FAIL: TestPanicHelper/1 (N.NNs) panic_test.go:NNN: TestPanicHelper/1 + TestPanicHelper/1 `, }, { desc: "subtest panics with outer cleanup panic", @@ -65,6 +70,7 @@ ran middle cleanup 1 ran outer cleanup --- FAIL: TestPanicHelper (N.NNs) panic_test.go:NNN: TestPanicHelper + TestPanicHelper `, }, { desc: "subtest panics with middle cleanup panic", @@ -75,8 +81,10 @@ ran middle cleanup 1 ran outer cleanup --- FAIL: TestPanicHelper (N.NNs) panic_test.go:NNN: TestPanicHelper + TestPanicHelper --- FAIL: TestPanicHelper/1 (N.NNs) panic_test.go:NNN: TestPanicHelper/1 + TestPanicHelper/1 `, }, { desc: "subtest panics with inner cleanup panic", @@ -87,8 +95,10 @@ ran middle cleanup 1 ran outer cleanup --- FAIL: TestPanicHelper (N.NNs) panic_test.go:NNN: TestPanicHelper + TestPanicHelper --- FAIL: TestPanicHelper/1 (N.NNs) panic_test.go:NNN: TestPanicHelper/1 + TestPanicHelper/1 `, }, { desc: "parallel subtest panics with cleanup", @@ -99,8 +109,10 @@ ran middle cleanup 1 ran outer cleanup --- FAIL: TestPanicHelper (N.NNs) panic_test.go:NNN: TestPanicHelper + TestPanicHelper --- FAIL: TestPanicHelper/1 (N.NNs) panic_test.go:NNN: TestPanicHelper/1 + TestPanicHelper/1 `, }, { desc: "parallel subtest panics with outer cleanup panic", @@ -111,6 +123,7 @@ ran middle cleanup 1 ran outer cleanup --- FAIL: TestPanicHelper (N.NNs) panic_test.go:NNN: TestPanicHelper + TestPanicHelper `, }, { desc: "parallel subtest panics with middle cleanup panic", @@ -121,8 +134,10 @@ ran middle cleanup 1 ran outer cleanup --- FAIL: TestPanicHelper (N.NNs) panic_test.go:NNN: TestPanicHelper + TestPanicHelper --- FAIL: TestPanicHelper/1 (N.NNs) panic_test.go:NNN: TestPanicHelper/1 + TestPanicHelper/1 `, }, { desc: "parallel subtest panics with inner cleanup panic", @@ -133,8 +148,10 @@ ran middle cleanup 1 ran outer cleanup --- FAIL: TestPanicHelper (N.NNs) panic_test.go:NNN: TestPanicHelper + TestPanicHelper --- FAIL: TestPanicHelper/1 (N.NNs) panic_test.go:NNN: TestPanicHelper/1 + TestPanicHelper/1 `, }} for _, tc := range testCases { @@ -165,6 +182,7 @@ func TestPanicHelper(t *testing.T) { return } t.Log(t.Name()) + t.Output().Write([]byte(t.Name())) if t.Name() == *testPanicTest { panic("panic") } @@ -195,6 +213,7 @@ func TestPanicHelper(t *testing.T) { t.Parallel() } t.Log(t.Name()) + t.Output().Write([]byte(t.Name())) if chosen { if *testPanicCleanup { t.Cleanup(func() { |
