From 81a74b4e8d4a1740529bb951eaa9569d429e4c0f Mon Sep 17 00:00:00 2001 From: Damien Neil Date: Thu, 30 May 2019 09:46:56 -0700 Subject: testing: provide additional information when test funcs panic Flush the output log up to the root when a test panics. Prior to this change, only the current test's output log was flushed to its parent, resulting in no output when a subtest panics. For the following test function: func Test(t *testing.T) { for i, test := range []int{1, 0, 2} { t.Run(fmt.Sprintf("%v/%v", i, test), func(t *testing.T) { _ = 1 / test }) } } Output before this change: panic: runtime error: integer divide by zero [recovered] panic: runtime error: integer divide by zero (stack trace follows) Output after this change: --- FAIL: Test (0.00s) --- FAIL: Test/1/0 (0.00s) panic: runtime error: integer divide by zero [recovered] (stack trace follows) Fixes #32121 Change-Id: Ifee07ccc005f0493a902190a8be734943123b6b7 Reviewed-on: https://go-review.googlesource.com/c/go/+/179599 Run-TryBot: Damien Neil TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/cmd/internal/test2json/testdata/panic.test | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/cmd/internal/test2json/testdata/panic.test (limited to 'src/cmd/internal/test2json/testdata/panic.test') diff --git a/src/cmd/internal/test2json/testdata/panic.test b/src/cmd/internal/test2json/testdata/panic.test new file mode 100644 index 0000000000..517ebafeb5 --- /dev/null +++ b/src/cmd/internal/test2json/testdata/panic.test @@ -0,0 +1,17 @@ +--- FAIL: TestPanic (0.00s) +panic: oops [recovered] + panic: oops + +goroutine 7 [running]: +testing.tRunner.func1(0xc000092100) + /go/src/testing/testing.go:874 +0x3a3 +panic(0x1110ea0, 0x116aea0) + /go/src/runtime/panic.go:679 +0x1b2 +command-line-arguments.TestPanic(0xc000092100) + a_test.go:6 +0x39 +testing.tRunner(0xc000092100, 0x114f500) + go/src/testing/testing.go:909 +0xc9 +created by testing.(*T).Run + go/src/testing/testing.go:960 +0x350 +FAIL command-line-arguments 0.042s +FAIL -- cgit v1.3