File tree Expand file tree Collapse file tree 3 files changed +30
-0
lines changed Expand file tree Collapse file tree 3 files changed +30
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -140,6 +140,18 @@ func TestRun(t *testing.T) {
140
140
})
141
141
}
142
142
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
+
143
155
func wantPanic (t * testing.T , want string ) {
144
156
if e := recover (); e != nil {
145
157
if got := fmt .Sprint (e ); got != want {
Original file line number Diff line number Diff line change @@ -1261,6 +1261,9 @@ func (c *common) Skipped() bool {
1261
1261
// When printing file and line information, that function will be skipped.
1262
1262
// Helper may be called simultaneously from multiple goroutines.
1263
1263
func (c * common ) Helper () {
1264
+ if c .isSynctest {
1265
+ c = c .parent
1266
+ }
1264
1267
c .mu .Lock ()
1265
1268
defer c .mu .Unlock ()
1266
1269
if c .helperPCs == nil {
You can’t perform that action at this time.
0 commit comments