]> Cypherpunks repositories - gostls13.git/commit
testing: provide additional information when test funcs panic
authorDamien Neil <dneil@google.com>
Thu, 30 May 2019 16:46:56 +0000 (09:46 -0700)
committerDamien Neil <dneil@google.com>
Wed, 30 Oct 2019 20:46:44 +0000 (20:46 +0000)
commit81a74b4e8d4a1740529bb951eaa9569d429e4c0f
treec54e366689ebc60a29901197517c4e1f6b3f5c9c
parentcd18da451faedc4218a5fd0e38f9b3d13aa5da01
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 <dneil@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/internal/test2json/testdata/panic.json [new file with mode: 0644]
src/cmd/internal/test2json/testdata/panic.test [new file with mode: 0644]
src/testing/panic_test.go [new file with mode: 0644]
src/testing/testing.go