diff options
author | Caleb Spare <cespare@gmail.com> | 2021-08-28 16:06:43 -0700 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2021-09-16 23:50:23 +0000 |
commit | 4efdaa7bc7220fad0177842d0009285ca429a823 (patch) | |
tree | 478323e4724c4134dae1c0f3b9d3d320f618f248 /src/testing/helperfuncs_test.go | |
parent | e09dcc211a338450d3f680fe39abc13b79ddbb29 (diff) | |
download | go-4efdaa7bc7220fad0177842d0009285ca429a823.tar.gz go-4efdaa7bc7220fad0177842d0009285ca429a823.zip |
testing: skip panics when picking the line number for decoration
Fixes #31154
Change-Id: I4cfd98b5e79f1abdc93044fb66855ac2cc0a9a49
Reviewed-on: https://go-review.googlesource.com/c/go/+/345909
Run-TryBot: Caleb Spare <cespare@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Carlos Amedee <carlos@golang.org>
Diffstat (limited to 'src/testing/helperfuncs_test.go')
-rw-r--r-- | src/testing/helperfuncs_test.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/testing/helperfuncs_test.go b/src/testing/helperfuncs_test.go index df0476ed73..272b33c0e5 100644 --- a/src/testing/helperfuncs_test.go +++ b/src/testing/helperfuncs_test.go @@ -65,6 +65,14 @@ func testHelper(t *T) { t.Helper() t.Error("9") }) + + // Check that helper-ness propagates up through subtests + // to helpers above. See https://golang.org/issue/44887. + helperSubCallingHelper(t, "11") + + // Check that helper-ness propagates up through panic/recover. + // See https://golang.org/issue/31154. + recoverHelper(t, "12") } func parallelTestHelper(t *T) { @@ -78,3 +86,27 @@ func parallelTestHelper(t *T) { } wg.Wait() } + +func helperSubCallingHelper(t *T, msg string) { + t.Helper() + t.Run("sub2", func(t *T) { + t.Helper() + t.Fatal(msg) + }) +} + +func recoverHelper(t *T, msg string) { + t.Helper() + defer func() { + t.Helper() + if err := recover(); err != nil { + t.Errorf("recover %s", err) + } + }() + doPanic(t, msg) +} + +func doPanic(t *T, msg string) { + t.Helper() + panic(msg) +} |