]> Cypherpunks repositories - gostls13.git/commitdiff
testing, testing/synctest: handle T.Helper in synctest bubbles
authorDamien Neil <dneil@google.com>
Fri, 20 Jun 2025 13:44:09 +0000 (14:44 +0100)
committerGopher Robot <gobot@golang.org>
Fri, 20 Jun 2025 19:29:58 +0000 (12:29 -0700)
Fixes #74199

Change-Id: I6a15fbd59a3a3f8c496440f56d09d695e1504e4e
Reviewed-on: https://go-review.googlesource.com/c/go/+/682576
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Auto-Submit: Damien Neil <dneil@google.com>

src/testing/synctest/helper_test.go [new file with mode: 0644]
src/testing/synctest/synctest_test.go
src/testing/testing.go

diff --git a/src/testing/synctest/helper_test.go b/src/testing/synctest/helper_test.go
new file mode 100644 (file)
index 0000000..7547d3e
--- /dev/null
@@ -0,0 +1,15 @@
+// Copyright 2025 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package synctest_test
+
+import "testing"
+
+// helperLog is a t.Helper which logs.
+// Since it is a helper, the log prefix should contain
+// the caller's file, not helper_test.go.
+func helperLog(t *testing.T, s string) {
+       t.Helper()
+       t.Log(s)
+}
index 822fd6fe1c72c42aa7458b63a403ccb99140c724..9c731787509fecab2869ad668f481936d3ccaaad 100644 (file)
@@ -140,6 +140,18 @@ func TestRun(t *testing.T) {
        })
 }
 
+func TestHelper(t *testing.T) {
+       runTest(t, []string{"-test.v"}, func() {
+               synctest.Test(t, func(t *testing.T) {
+                       helperLog(t, "log in helper")
+               })
+       }, `^=== RUN   TestHelper
+    synctest_test.go:.* log in helper
+--- PASS: TestHelper.*
+PASS
+$`)
+}
+
 func wantPanic(t *testing.T, want string) {
        if e := recover(); e != nil {
                if got := fmt.Sprint(e); got != want {
index b2d4c0c938af813129a9e115a1af59265366c849..3475bfca4a6976cdd2d2e0a80702583d2585ab13 100644 (file)
@@ -1261,6 +1261,9 @@ func (c *common) Skipped() bool {
 // When printing file and line information, that function will be skipped.
 // Helper may be called simultaneously from multiple goroutines.
 func (c *common) Helper() {
+       if c.isSynctest {
+               c = c.parent
+       }
        c.mu.Lock()
        defer c.mu.Unlock()
        if c.helperPCs == nil {