From 004858ccddb2f092d3413e96ba8526a8df8e3906 Mon Sep 17 00:00:00 2001 From: Michael Anthony Knyszek Date: Thu, 11 Sep 2025 23:48:04 +0000 Subject: [PATCH] all: replace os.Getenv("GO_BUILDER_NAME") with testenv.Builder in tests Some tests still reach for GO_BUILDER_NAME directly. This change makes it so that they go through testenv.Builder. There are a couple more, but changing them may also cause tests to start failing. Done in a follow-up. Change-Id: Id2453b7b62f5ebf3594e92fa53724a577a97440f Reviewed-on: https://go-review.googlesource.com/c/go/+/703135 Reviewed-by: Dmitri Shuralyov Reviewed-by: Dmitri Shuralyov LUCI-TryBot-Result: Go LUCI --- src/cmd/cgo/internal/testcarchive/carchive_test.go | 2 +- src/cmd/cgo/internal/testcshared/cshared_test.go | 2 +- src/cmd/cgo/internal/testplugin/plugin_test.go | 2 +- src/cmd/cgo/internal/testshared/shared_test.go | 4 ++-- src/cmd/link/link_test.go | 2 +- src/syscall/getdirentries_test.go | 3 ++- 6 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/cmd/cgo/internal/testcarchive/carchive_test.go b/src/cmd/cgo/internal/testcarchive/carchive_test.go index 155eca9a73..c0ad79f231 100644 --- a/src/cmd/cgo/internal/testcarchive/carchive_test.go +++ b/src/cmd/cgo/internal/testcarchive/carchive_test.go @@ -58,7 +58,7 @@ func TestMain(m *testing.M) { } func testMain(m *testing.M) int { - if testing.Short() && os.Getenv("GO_BUILDER_NAME") == "" { + if testing.Short() && testenv.Builder() == "" { globalSkip = func(t testing.TB) { t.Skip("short mode and $GO_BUILDER_NAME not set") } return m.Run() } diff --git a/src/cmd/cgo/internal/testcshared/cshared_test.go b/src/cmd/cgo/internal/testcshared/cshared_test.go index 096959562c..2c4d33f599 100644 --- a/src/cmd/cgo/internal/testcshared/cshared_test.go +++ b/src/cmd/cgo/internal/testcshared/cshared_test.go @@ -44,7 +44,7 @@ func TestMain(m *testing.M) { func testMain(m *testing.M) int { log.SetFlags(log.Lshortfile) flag.Parse() - if testing.Short() && os.Getenv("GO_BUILDER_NAME") == "" { + if testing.Short() && testenv.Builder() == "" { globalSkip = func(t *testing.T) { t.Skip("short mode and $GO_BUILDER_NAME not set") } return m.Run() } diff --git a/src/cmd/cgo/internal/testplugin/plugin_test.go b/src/cmd/cgo/internal/testplugin/plugin_test.go index 5bff81092c..2afb542ec4 100644 --- a/src/cmd/cgo/internal/testplugin/plugin_test.go +++ b/src/cmd/cgo/internal/testplugin/plugin_test.go @@ -46,7 +46,7 @@ func prettyPrintf(format string, args ...interface{}) { } func testMain(m *testing.M) int { - if testing.Short() && os.Getenv("GO_BUILDER_NAME") == "" { + if testing.Short() && testenv.Builder() == "" { globalSkip = func(t *testing.T) { t.Skip("short mode and $GO_BUILDER_NAME not set") } return m.Run() } diff --git a/src/cmd/cgo/internal/testshared/shared_test.go b/src/cmd/cgo/internal/testshared/shared_test.go index e927460376..3d401b604e 100644 --- a/src/cmd/cgo/internal/testshared/shared_test.go +++ b/src/cmd/cgo/internal/testshared/shared_test.go @@ -96,7 +96,7 @@ func goCmd(t *testing.T, args ...string) string { // TestMain calls testMain so that the latter can use defer (TestMain exits with os.Exit). func testMain(m *testing.M) (int, error) { - if testing.Short() && os.Getenv("GO_BUILDER_NAME") == "" { + if testing.Short() && testenv.Builder() == "" { globalSkip = func(t testing.TB) { t.Skip("short mode and $GO_BUILDER_NAME not set") } return m.Run(), nil } @@ -554,7 +554,7 @@ func checkPIE(t *testing.T, name string) { } func TestTrivialPIE(t *testing.T) { - if strings.HasSuffix(os.Getenv("GO_BUILDER_NAME"), "-alpine") { + if strings.Contains(testenv.Builder(), "-alpine") { t.Skip("skipping on alpine until issue #54354 resolved") } globalSkip(t) diff --git a/src/cmd/link/link_test.go b/src/cmd/link/link_test.go index a87d452ed3..0125ba8e0f 100644 --- a/src/cmd/link/link_test.go +++ b/src/cmd/link/link_test.go @@ -280,7 +280,7 @@ func TestBuildForTvOS(t *testing.T) { if runtime.GOOS != "darwin" { t.Skip("skipping on non-darwin platform") } - if testing.Short() && os.Getenv("GO_BUILDER_NAME") == "" { + if testing.Short() && testenv.Builder() == "" { t.Skip("skipping in -short mode with $GO_BUILDER_NAME empty") } if err := testenv.Command(t, "xcrun", "--help").Run(); err != nil { diff --git a/src/syscall/getdirentries_test.go b/src/syscall/getdirentries_test.go index b5361ddaef..f879e2a539 100644 --- a/src/syscall/getdirentries_test.go +++ b/src/syscall/getdirentries_test.go @@ -8,6 +8,7 @@ package syscall_test import ( "fmt" + "internal/testenv" "os" "path/filepath" "slices" @@ -24,7 +25,7 @@ func TestGetdirentries(t *testing.T) { } } func testGetdirentries(t *testing.T, count int) { - if count > 100 && testing.Short() && os.Getenv("GO_BUILDER_NAME") == "" { + if count > 100 && testing.Short() && testenv.Builder() == "" { t.Skip("skipping in -short mode") } d := t.TempDir() -- 2.52.0