Skip to content

Commit 49cdf0c

Browse files
neildgopherbot
authored andcommitted
testing, testing/synctest: handle T.Helper in synctest bubbles
Fixes #74199 Change-Id: I6a15fbd59a3a3f8c496440f56d09d695e1504e4e Reviewed-on: https://go-review.googlesource.com/c/go/+/682576 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Alan Donovan <[email protected]> Auto-Submit: Damien Neil <[email protected]>
1 parent 3bf1eec commit 49cdf0c

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

src/testing/synctest/helper_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2025 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.
4+
5+
package synctest_test
6+
7+
import "testing"
8+
9+
// helperLog is a t.Helper which logs.
10+
// Since it is a helper, the log prefix should contain
11+
// the caller's file, not helper_test.go.
12+
func helperLog(t *testing.T, s string) {
13+
t.Helper()
14+
t.Log(s)
15+
}

src/testing/synctest/synctest_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,18 @@ func TestRun(t *testing.T) {
140140
})
141141
}
142142

143+
func TestHelper(t *testing.T) {
144+
runTest(t, []string{"-test.v"}, func() {
145+
synctest.Test(t, func(t *testing.T) {
146+
helperLog(t, "log in helper")
147+
})
148+
}, `^=== RUN TestHelper
149+
synctest_test.go:.* log in helper
150+
--- PASS: TestHelper.*
151+
PASS
152+
$`)
153+
}
154+
143155
func wantPanic(t *testing.T, want string) {
144156
if e := recover(); e != nil {
145157
if got := fmt.Sprint(e); got != want {

src/testing/testing.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,9 @@ func (c *common) Skipped() bool {
12611261
// When printing file and line information, that function will be skipped.
12621262
// Helper may be called simultaneously from multiple goroutines.
12631263
func (c *common) Helper() {
1264+
if c.isSynctest {
1265+
c = c.parent
1266+
}
12641267
c.mu.Lock()
12651268
defer c.mu.Unlock()
12661269
if c.helperPCs == nil {

0 commit comments

Comments
 (0)