1 // Copyright 2017 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
9 // The line numbering of this file is important for TestTBHelper.
11 func notHelper(t *T, msg string) {
15 func helper(t *T, msg string) {
20 func notHelperCallingHelper(t *T, msg string) {
24 func helperCallingHelper(t *T, msg string) {
29 func genericHelper[G any](t *T, msg string) {
34 var genericIntHelper = genericHelper[int]
36 func testHelper(t *T) {
37 // Check combinations of directly and indirectly
38 // calling helper functions.
41 notHelperCallingHelper(t, "2")
42 helperCallingHelper(t, "3")
44 // Check a function literal closing over t that uses Helper.
45 fn := func(msg string) {
51 t.Run("sub", func(t *T) {
53 notHelperCallingHelper(t, "6")
54 // Check that calling Helper from inside a subtest entry function
55 // works as if it were in an ordinary function call.
60 // Check that calling Helper from inside a top-level test function
65 // Check that right caller is reported for func passed to Cleanup when
66 // multiple cleanup functions have been registered.
76 // Check that helper-ness propagates up through subtests
77 // to helpers above. See https://golang.org/issue/44887.
78 helperSubCallingHelper(t, "11")
80 // Check that helper-ness propagates up through panic/recover.
81 // See https://golang.org/issue/31154.
82 recoverHelper(t, "12")
84 genericHelper[float64](t, "GenericFloat64")
85 genericIntHelper(t, "GenericInt")
88 func parallelTestHelper(t *T) {
90 for i := 0; i < 5; i++ {
93 notHelperCallingHelper(t, "parallel")
100 func helperSubCallingHelper(t *T, msg string) {
102 t.Run("sub2", func(t *T) {
108 func recoverHelper(t *T, msg string) {
112 if err := recover(); err != nil {
113 t.Errorf("recover %s", err)
119 func doPanic(t *T, msg string) {