From 9e026bf9cc1dcb6ef24d26398182a22d9d6cd2d2 Mon Sep 17 00:00:00 2001 From: suntala Date: Tue, 13 May 2025 21:30:35 +0000 Subject: 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. This fixes and expands on https://go-review.googlesource.com/c/go/+/646956. For #59928. Change-Id: I08179c35a681f601cf125c0f4aeb648bc10c7a9f GitHub-Last-Rev: e6e202793c9bc471493187e0556a3a1e7305ff82 GitHub-Pull-Request: golang/go#73703 Reviewed-on: https://go-review.googlesource.com/c/go/+/672395 LUCI-TryBot-Result: Go LUCI Auto-Submit: Alan Donovan Reviewed-by: Alan Donovan Reviewed-by: Dmitri Shuralyov Auto-Submit: Jonathan Amsterdam --- src/testing/panic_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/testing/panic_test.go') 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() { -- cgit v1.3