aboutsummaryrefslogtreecommitdiff
path: root/src/testing/helperfuncs_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/helperfuncs_test.go')
-rw-r--r--src/testing/helperfuncs_test.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/testing/helperfuncs_test.go b/src/testing/helperfuncs_test.go
index df0476ed732..272b33c0e50 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)
+}