From 76a42d74356e3c5bee0851c99665b21bf29f0c27 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Thu, 29 Aug 2024 18:23:25 -0700 Subject: [PATCH] internal/testenv: add missing t.Helper calls ...and move a few so they won't be called when not needed. Change-Id: I024b9552ed5ed839cde4fbae4815ec6ba8b67265 Reviewed-on: https://go-review.googlesource.com/c/go/+/609300 Reviewed-by: Ian Lance Taylor Reviewed-by: Dmitri Shuralyov Auto-Submit: Ian Lance Taylor LUCI-TryBot-Result: Go LUCI --- src/internal/testenv/exec.go | 2 ++ src/internal/testenv/testenv.go | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/internal/testenv/exec.go b/src/internal/testenv/exec.go index 0e6a5f9a1a6..9f21b323abb 100644 --- a/src/internal/testenv/exec.go +++ b/src/internal/testenv/exec.go @@ -32,6 +32,7 @@ import ( // for the resulting error. func MustHaveExec(t testing.TB) { if err := tryExec(); err != nil { + t.Helper() t.Skipf("skipping test: cannot exec subprocess on %s/%s: %v", runtime.GOOS, runtime.GOARCH, err) } } @@ -103,6 +104,7 @@ func MustHaveExecPath(t testing.TB, path string) { err, _ = execPaths.LoadOrStore(path, err) } if err != nil { + t.Helper() t.Skipf("skipping test: %s: %s", path, err) } } diff --git a/src/internal/testenv/testenv.go b/src/internal/testenv/testenv.go index 80da6e6c57b..e07e71a9b25 100644 --- a/src/internal/testenv/testenv.go +++ b/src/internal/testenv/testenv.go @@ -131,6 +131,7 @@ func HasGoRun() bool { // If not, MustHaveGoRun calls t.Skip with an explanation. func MustHaveGoRun(t testing.TB) { if !HasGoRun() { + t.Helper() t.Skipf("skipping test: 'go run' not available on %s/%s", runtime.GOOS, runtime.GOARCH) } } @@ -150,6 +151,7 @@ func HasParallelism() bool { // threads in parallel. If not, MustHaveParallelism calls t.Skip with an explanation. func MustHaveParallelism(t testing.TB) { if !HasParallelism() { + t.Helper() t.Skipf("skipping test: no parallelism available on %s/%s", runtime.GOOS, runtime.GOARCH) } } @@ -321,6 +323,7 @@ var hasCgo = sync.OnceValue(func() bool { // MustHaveCGO calls t.Skip if cgo is not available. func MustHaveCGO(t testing.TB) { if !HasCGO() { + t.Helper() t.Skipf("skipping test: no cgo") } } @@ -336,6 +339,7 @@ func CanInternalLink(withCgo bool) bool { // If not, MustInternalLink calls t.Skip with an explanation. func MustInternalLink(t testing.TB, withCgo bool) { if !CanInternalLink(withCgo) { + t.Helper() if withCgo && CanInternalLink(false) { t.Skipf("skipping test: internal linking on %s/%s is not supported with cgo", runtime.GOOS, runtime.GOARCH) } @@ -348,6 +352,7 @@ func MustInternalLink(t testing.TB, withCgo bool) { // If not, MustInternalLinkPIE calls t.Skip with an explanation. func MustInternalLinkPIE(t testing.TB) { if !platform.InternalLinkPIESupported(runtime.GOOS, runtime.GOARCH) { + t.Helper() t.Skipf("skipping test: internal linking for buildmode=pie on %s/%s is not supported", runtime.GOOS, runtime.GOARCH) } } @@ -357,6 +362,7 @@ func MustInternalLinkPIE(t testing.TB) { // If not, MustHaveBuildMode calls t.Skip with an explanation. func MustHaveBuildMode(t testing.TB, buildmode string) { if !platform.BuildModeSupported(runtime.Compiler, buildmode, runtime.GOOS, runtime.GOARCH) { + t.Helper() t.Skipf("skipping test: build mode %s on %s/%s is not supported by the %s compiler", buildmode, runtime.GOOS, runtime.GOARCH, runtime.Compiler) } } @@ -372,6 +378,7 @@ func HasSymlink() bool { func MustHaveSymlink(t testing.TB) { ok, reason := hasSymlink() if !ok { + t.Helper() t.Skipf("skipping test: cannot make symlinks on %s/%s: %s", runtime.GOOS, runtime.GOARCH, reason) } } @@ -388,6 +395,7 @@ func HasLink() bool { // If not, MustHaveLink calls t.Skip with an explanation. func MustHaveLink(t testing.TB) { if !HasLink() { + t.Helper() t.Skipf("skipping test: hardlinks are not supported on %s/%s", runtime.GOOS, runtime.GOARCH) } } @@ -395,15 +403,15 @@ func MustHaveLink(t testing.TB) { var flaky = flag.Bool("flaky", false, "run known-flaky tests too") func SkipFlaky(t testing.TB, issue int) { - t.Helper() if !*flaky { + t.Helper() t.Skipf("skipping known flaky test without the -flaky flag; see golang.org/issue/%d", issue) } } func SkipFlakyNet(t testing.TB) { - t.Helper() if v, _ := strconv.ParseBool(os.Getenv("GO_BUILDER_FLAKY_NET")); v { + t.Helper() t.Skip("skipping test on builder known to have frequent network failures") } }