Skip to content

Commit b49843a

Browse files
committed
testing: fix Helper line number change
parent's helperNames has not been set when frameSkip called, moving helperNames initilazing to frameSkip. Fixes #44887
1 parent b00dcf0 commit b49843a

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/testing/helper_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,44 @@ helperfuncs_test.go:60: 10
4949
}
5050
}
5151

52+
func TestTBHelperLineNumer(t *T) {
53+
var buf bytes.Buffer
54+
ctx := newTestContext(1, newMatcher(regexp.MatchString, "", ""))
55+
t1 := &T{
56+
common: common{
57+
signal: make(chan bool),
58+
w: &buf,
59+
},
60+
context: ctx,
61+
}
62+
t1.Run("Test", func(t *T) {
63+
helperA := func(t *T) {
64+
t.Helper()
65+
t.Run("subtest", func(t *T) {
66+
t.Helper()
67+
t.Fatal("fatal error message")
68+
})
69+
}
70+
helperA(t)
71+
})
72+
73+
want := `--- FAIL: Test (?s)
74+
--- FAIL: Test/subtest (?s)
75+
helper_test.go:70: fatal error message
76+
`
77+
lines := strings.Split(buf.String(), "\n")
78+
durationRE := regexp.MustCompile(`\(.*\)$`)
79+
for i, line := range lines {
80+
line = strings.TrimSpace(line)
81+
line = durationRE.ReplaceAllString(line, "(?s)")
82+
lines[i] = line
83+
}
84+
got := strings.Join(lines, "\n")
85+
if got != want {
86+
t.Errorf("got output:\n\n%v\nwant:\n\n%v", got, want)
87+
}
88+
}
89+
5290
func TestTBHelperParallel(t *T) {
5391
var buf bytes.Buffer
5492
ctx := newTestContext(1, newMatcher(regexp.MatchString, "", ""))

0 commit comments

Comments
 (0)