]> Cypherpunks repositories - gostls13.git/commitdiff
all: use testenv.GoToolPath instead of hardcoding go
authorqmuntal <quimmuntal@gmail.com>
Mon, 24 Feb 2025 09:21:01 +0000 (10:21 +0100)
committerQuim Muntal <quimmuntal@gmail.com>
Tue, 25 Feb 2025 20:01:35 +0000 (12:01 -0800)
Change-Id: I84ec73d3ddef913a87cb9b48147c44ac3e7c8a8d
Reviewed-on: https://go-review.googlesource.com/c/go/+/651957
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

16 files changed:
src/cmd/cgo/internal/swig/swig_test.go
src/cmd/cgo/internal/testcarchive/carchive_test.go
src/cmd/cgo/internal/testcshared/cshared_test.go
src/cmd/cgo/internal/testerrors/argposition_test.go
src/cmd/cgo/internal/testerrors/badsym_test.go
src/cmd/cgo/internal/testerrors/errors_test.go
src/cmd/cgo/internal/testerrors/ptr_test.go
src/cmd/cgo/internal/testfortran/fortran_test.go
src/cmd/cgo/internal/testgodefs/testgodefs_test.go
src/cmd/cgo/internal/testlife/life_test.go
src/cmd/cgo/internal/testso/so_test.go
src/cmd/cgo/internal/teststdio/stdio_test.go
src/cmd/compile/internal/importer/gcimporter_test.go
src/internal/godebug/godebug_test.go
src/runtime/internal/wasitest/nonblock_test.go
src/runtime/internal/wasitest/tcpecho_test.go

index 923378b2dd8fb0569a0af674bdc0d23e3db2a7b7..603dab4917c263cbf80f5dbad5d1ed6f3f84ce9d 100644 (file)
@@ -40,8 +40,9 @@ func TestCallback(t *testing.T) {
 }
 
 func run(t *testing.T, dir string, lto bool, args ...string) {
+       testenv.MustHaveGoRun(t)
        runArgs := append([]string{"run", "."}, args...)
-       cmd := exec.Command("go", runArgs...)
+       cmd := exec.Command(testenv.GoToolPath(t), runArgs...)
        cmd.Dir = dir
        if lto {
                // On the builders we're using the default /usr/bin/ld, but
@@ -68,7 +69,7 @@ func run(t *testing.T, dir string, lto bool, args ...string) {
 
 func mustHaveCxx(t *testing.T) {
        // Ask the go tool for the CXX it's configured to use.
-       cxx, err := exec.Command("go", "env", "CXX").CombinedOutput()
+       cxx, err := exec.Command(testenv.GoToolPath(t), "env", "CXX").CombinedOutput()
        if err != nil {
                t.Fatalf("go env CXX failed: %s", err)
        }
index c263b82d5768f40022bb762c3b2a54802fa1be4e..155eca9a73bdb2b38f7bd3e7b03d74c5453c1033 100644 (file)
@@ -218,7 +218,7 @@ func genHeader(t *testing.T, header, dir string) {
                t.Fatal(err)
        }
 
-       cmd := exec.Command("go", "tool", "cgo",
+       cmd := exec.Command(testenv.GoToolPath(t), "tool", "cgo",
                "-objdir", objDir,
                "-exportheader", header)
        cmd.Args = append(cmd.Args, files...)
@@ -524,7 +524,7 @@ func TestEarlySignalHandler(t *testing.T) {
                }()
        }
 
-       cmd := exec.Command("go", "build", "-buildmode=c-archive", "-o", "libgo2.a", "./libgo2")
+       cmd := exec.Command(testenv.GoToolPath(t), "build", "-buildmode=c-archive", "-o", "libgo2.a", "./libgo2")
        if out, err := cmd.CombinedOutput(); err != nil {
                t.Logf("%s", out)
                t.Fatal(err)
@@ -674,7 +674,7 @@ func buildSignalForwardingTest(t *testing.T) {
        }
 
        t.Log("go build -buildmode=c-archive -o libgo2.a ./libgo2")
-       cmd := exec.Command("go", "build", "-buildmode=c-archive", "-o", "libgo2.a", "./libgo2")
+       cmd := exec.Command(testenv.GoToolPath(t), "build", "-buildmode=c-archive", "-o", "libgo2.a", "./libgo2")
        out, err := cmd.CombinedOutput()
        if len(out) > 0 {
                t.Logf("%s", out)
@@ -801,7 +801,7 @@ func TestOsSignal(t *testing.T) {
                }()
        }
 
-       cmd := exec.Command("go", "build", "-buildmode=c-archive", "-o", "libgo3.a", "./libgo3")
+       cmd := exec.Command(testenv.GoToolPath(t), "build", "-buildmode=c-archive", "-o", "libgo3.a", "./libgo3")
        if out, err := cmd.CombinedOutput(); err != nil {
                t.Logf("%s", out)
                t.Fatal(err)
@@ -843,7 +843,7 @@ func TestSigaltstack(t *testing.T) {
                }()
        }
 
-       cmd := exec.Command("go", "build", "-buildmode=c-archive", "-o", "libgo4.a", "./libgo4")
+       cmd := exec.Command(testenv.GoToolPath(t), "build", "-buildmode=c-archive", "-o", "libgo4.a", "./libgo4")
        if out, err := cmd.CombinedOutput(); err != nil {
                t.Logf("%s", out)
                t.Fatal(err)
@@ -908,7 +908,7 @@ func TestExtar(t *testing.T) {
                t.Fatal(err)
        }
 
-       cmd := exec.Command("go", "build", "-buildmode=c-archive", "-ldflags=-extar="+filepath.Join(dir, "testar"), "-o", "libgo4.a", "./libgo4")
+       cmd := exec.Command(testenv.GoToolPath(t), "build", "-buildmode=c-archive", "-ldflags=-extar="+filepath.Join(dir, "testar"), "-o", "libgo4.a", "./libgo4")
        if out, err := cmd.CombinedOutput(); err != nil {
                t.Logf("%s", out)
                t.Fatal(err)
@@ -955,7 +955,7 @@ func TestPIE(t *testing.T) {
        // be running this test in a GOROOT owned by root.)
        genHeader(t, "p.h", "./p")
 
-       cmd := exec.Command("go", "build", "-buildmode=c-archive", "./libgo")
+       cmd := exec.Command(testenv.GoToolPath(t), "build", "-buildmode=c-archive", "./libgo")
        if out, err := cmd.CombinedOutput(); err != nil {
                t.Logf("%s", out)
                t.Fatal(err)
@@ -1042,7 +1042,7 @@ func TestSIGPROF(t *testing.T) {
                }()
        }
 
-       cmd := exec.Command("go", "build", "-buildmode=c-archive", "-o", "libgo6.a", "./libgo6")
+       cmd := exec.Command(testenv.GoToolPath(t), "build", "-buildmode=c-archive", "-o", "libgo6.a", "./libgo6")
        out, err := cmd.CombinedOutput()
        t.Logf("%v\n%s", cmd.Args, out)
        if err != nil {
@@ -1089,7 +1089,7 @@ func TestCompileWithoutShared(t *testing.T) {
                }()
        }
 
-       cmd := exec.Command("go", "build", "-buildmode=c-archive", "-gcflags=-shared=false", "-o", "libgo2.a", "./libgo2")
+       cmd := exec.Command(testenv.GoToolPath(t), "build", "-buildmode=c-archive", "-gcflags=-shared=false", "-o", "libgo2.a", "./libgo2")
        out, err := cmd.CombinedOutput()
        t.Logf("%v\n%s", cmd.Args, out)
        if err != nil {
@@ -1204,7 +1204,7 @@ func TestManyCalls(t *testing.T) {
                }()
        }
 
-       cmd := exec.Command("go", "build", "-buildmode=c-archive", "-o", "libgo7.a", "./libgo7")
+       cmd := exec.Command(testenv.GoToolPath(t), "build", "-buildmode=c-archive", "-o", "libgo7.a", "./libgo7")
        out, err := cmd.CombinedOutput()
        t.Logf("%v\n%s", cmd.Args, out)
        if err != nil {
@@ -1259,7 +1259,7 @@ func TestPreemption(t *testing.T) {
                }()
        }
 
-       cmd := exec.Command("go", "build", "-buildmode=c-archive", "-o", "libgo8.a", "./libgo8")
+       cmd := exec.Command(testenv.GoToolPath(t), "build", "-buildmode=c-archive", "-o", "libgo8.a", "./libgo8")
        out, err := cmd.CombinedOutput()
        t.Logf("%v\n%s", cmd.Args, out)
        if err != nil {
@@ -1309,7 +1309,7 @@ func TestDeepStack(t *testing.T) {
                }()
        }
 
-       cmd := exec.Command("go", "build", "-buildmode=c-archive", "-o", "libgo9.a", "./libgo9")
+       cmd := exec.Command(testenv.GoToolPath(t), "build", "-buildmode=c-archive", "-o", "libgo9.a", "./libgo9")
        out, err := cmd.CombinedOutput()
        t.Logf("%v\n%s", cmd.Args, out)
        if err != nil {
@@ -1372,7 +1372,7 @@ func BenchmarkCgoCallbackMainThread(b *testing.B) {
                }()
        }
 
-       cmd := exec.Command("go", "build", "-buildmode=c-archive", "-o", "libgo10.a", "./libgo10")
+       cmd := exec.Command(testenv.GoToolPath(b), "build", "-buildmode=c-archive", "-o", "libgo10.a", "./libgo10")
        out, err := cmd.CombinedOutput()
        b.Logf("%v\n%s", cmd.Args, out)
        if err != nil {
@@ -1414,7 +1414,7 @@ func TestSharedObject(t *testing.T) {
                }()
        }
 
-       cmd := exec.Command("go", "build", "-buildmode=c-archive", "-o", "libgo_s.a", "./libgo")
+       cmd := exec.Command(testenv.GoToolPath(t), "build", "-buildmode=c-archive", "-o", "libgo_s.a", "./libgo")
        out, err := cmd.CombinedOutput()
        t.Logf("%v\n%s", cmd.Args, out)
        if err != nil {
index 9fe5e791feb16f94092246fabd40801d5c6c65dc..096959562c02f2e27449a1aeecda6d030b13b4af 100644 (file)
@@ -407,7 +407,7 @@ func main() {
                argv = append(argv, "-ldflags", "-extldflags=-Wl,--export-all-symbols")
        }
        argv = append(argv, "-o", objfile, srcfile)
-       out, err := exec.Command("go", argv...).CombinedOutput()
+       out, err := exec.Command(testenv.GoToolPath(t), argv...).CombinedOutput()
        if err != nil {
                t.Fatalf("build failure: %s\n%s\n", err, string(out))
        }
index 714f9b45f84f4957af824861e1f3113cf0d99d44..035552127b8f466d489826fcc7822ab6ffa2afa6 100644 (file)
@@ -81,7 +81,7 @@ func TestArgumentsPositions(t *testing.T) {
                t.Fatal(err)
        }
 
-       cmd := exec.Command("go", "tool", "cgo",
+       cmd := exec.Command(testenv.GoToolPath(t), "tool", "cgo",
                "-srcdir", testdata,
                "-objdir", dir,
                "issue42580.go")
index 6c87977bd1dcc1061704b107cfbdaa6bee5078b7..4fd5c44505aa7834be240ccfd4556a68751216e5 100644 (file)
@@ -136,7 +136,7 @@ func TestBadSymbol(t *testing.T) {
        makeFile(godir, "go.mod", "module badsym")
 
        // Try to build our little package.
-       cmd := exec.Command("go", "build", "-ldflags=-v")
+       cmd := exec.Command(testenv.GoToolPath(t), "build", "-ldflags=-v")
        cmd.Dir = godir
        output, err := cmd.CombinedOutput()
 
index 941c7eff201245b1bbdadb13db95b141c45ff8ad..1a0de6da03d34bcb9b97f772aa73e29e473811fd 100644 (file)
@@ -76,7 +76,7 @@ func expect(t *testing.T, errors []*regexp.Regexp, files ...string) {
        for _, file := range files {
                args = append(args, path(file))
        }
-       cmd := exec.Command("go", args...)
+       cmd := exec.Command(testenv.GoToolPath(t), args...)
        out, err := cmd.CombinedOutput()
        if err == nil {
                t.Errorf("expected cgo to fail but it succeeded")
@@ -105,7 +105,7 @@ func expect(t *testing.T, errors []*regexp.Regexp, files ...string) {
 func sizeofLongDouble(t *testing.T) int {
        testenv.MustHaveGoRun(t)
        testenv.MustHaveCGO(t)
-       cmd := exec.Command("go", "run", path("long_double_size.go"))
+       cmd := exec.Command(testenv.GoToolPath(t), "run", path("long_double_size.go"))
        out, err := cmd.CombinedOutput()
        if err != nil {
                t.Fatalf("%#q: %v:\n%s", strings.Join(cmd.Args, " "), err, out)
@@ -158,7 +158,7 @@ func TestToleratesOptimizationFlag(t *testing.T) {
                        testenv.MustHaveCGO(t)
                        t.Parallel()
 
-                       cmd := exec.Command("go", "build", path("issue14669.go"))
+                       cmd := exec.Command(testenv.GoToolPath(t), "build", path("issue14669.go"))
                        cmd.Env = append(os.Environ(), "CGO_CFLAGS="+cflags)
                        out, err := cmd.CombinedOutput()
                        if err != nil {
@@ -173,7 +173,7 @@ func TestMallocCrashesOnNil(t *testing.T) {
        testenv.MustHaveGoRun(t)
        t.Parallel()
 
-       cmd := exec.Command("go", "run", path("malloc.go"))
+       cmd := exec.Command(testenv.GoToolPath(t), "run", path("malloc.go"))
        out, err := cmd.CombinedOutput()
        if err == nil {
                t.Logf("%#q:\n%s", strings.Join(cmd.Args, " "), out)
index 9a8187f55f20f18827b6c6c0a48d694e219ac9dc..beba0d26ac1818d6a7a93da7dca505fe272b2742 100644 (file)
@@ -609,7 +609,7 @@ func buildPtrTests(t *testing.T, gopath string, cgocheck2 bool) (exe string) {
        if cgocheck2 {
                exeName = "ptrtest2.exe"
        }
-       cmd := exec.Command("go", "build", "-o", exeName)
+       cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", exeName)
        cmd.Dir = src
        cmd.Env = append(os.Environ(), "GOPATH="+gopath)
 
index 0eae7c5f53d4aa1a78a6b834bd99fd078d4d89be..9ccf916d841d664fe2d82d6739b611c8ef173ca3 100644 (file)
@@ -75,7 +75,7 @@ func TestFortran(t *testing.T) {
        // Finally, run the actual test.
        t.Log("go", "run", "./testdata/testprog")
        var stdout, stderr strings.Builder
-       cmd := exec.Command("go", "run", "./testdata/testprog")
+       cmd := exec.Command(testenv.GoToolPath(t), "run", "./testdata/testprog")
        cmd.Stdout = &stdout
        cmd.Stderr = &stderr
        err := cmd.Run()
index 8138b7fa3d5a5fe611fbe19f27e5d02a2baab594..0ee953f57fe6764ed41042c5346d2ff6ef9db6d4 100644 (file)
@@ -51,7 +51,7 @@ func TestGoDefs(t *testing.T) {
        }
 
        for _, fp := range filePrefixes {
-               cmd := exec.Command("go", "tool", "cgo",
+               cmd := exec.Command(testenv.GoToolPath(t), "tool", "cgo",
                        "-godefs",
                        "-srcdir", testdata,
                        "-objdir", dir,
@@ -107,7 +107,7 @@ func TestGoDefs(t *testing.T) {
        // instead of invoking 'go build' and the resulting binary separately, so that
        // this test can pass on mobile builders, which do not copy artifacts back
        // from remote invocations.
-       cmd := exec.Command("go", "run", ".")
+       cmd := exec.Command(testenv.GoToolPath(t), "run", ".")
        cmd.Env = append(os.Environ(), "GOPATH="+gopath)
        cmd.Dir = dir
        if out, err := cmd.CombinedOutput(); err != nil {
index e93d29c4d978b7658aedb985ace73cb96c84123e..3b8f57099548c0ab07978432fd88b1482632a175 100644 (file)
@@ -50,7 +50,7 @@ func TestTestRun(t *testing.T) {
        testenv.MustHaveGoRun(t)
        testenv.MustHaveCGO(t)
 
-       cmd := exec.Command("go", "run", "main.go")
+       cmd := exec.Command(testenv.GoToolPath(t), "run", "main.go")
        got, err := cmd.CombinedOutput()
        if err != nil {
                t.Fatalf("%v: %s\n%s", cmd, err, got)
index e011167f388ed3656f909a435c53830e29f61d9b..2be7807f773044ab7f333fb45d5cd7e5bc6168bb 100644 (file)
@@ -104,7 +104,7 @@ func testSO(t *testing.T, dir string) {
                }
        }
 
-       cmd = exec.Command("go", "build", "-o", "main.exe", "main.go")
+       cmd = exec.Command(testenv.GoToolPath(t), "build", "-o", "main.exe", "main.go")
        cmd.Dir = modRoot
        cmd.Env = append(os.Environ(), "GOPATH="+GOPATH)
        out, err = cmd.CombinedOutput()
index 3883422d6f08ac77b8cba6ac01d1fb85e9ab0f32..9150281ae87ff37fbb5b459d3976756b129f6c20 100644 (file)
@@ -59,7 +59,7 @@ func TestTestRun(t *testing.T) {
                file := file
                wantFile := strings.Replace(file, ".go", ".out", 1)
                t.Run(file, func(t *testing.T) {
-                       cmd := exec.Command("go", "run", file)
+                       cmd := exec.Command(testenv.GoToolPath(t), "run", file)
                        got, err := cmd.CombinedOutput()
                        if err != nil {
                                t.Fatalf("%v: %s\n%s", cmd, err, got)
index d913d3ca76ff1c7e9d5955b5300ef7cd4c341761..5d61b6608968bdede4ace01a3ce919cc25ed41f1 100644 (file)
@@ -243,7 +243,7 @@ func TestImportStdLib(t *testing.T) {
 
        // Get list of packages in stdlib. Filter out test-only packages with {{if .GoFiles}} check.
        var stderr bytes.Buffer
-       cmd := exec.Command("go", "list", "-f", "{{if .GoFiles}}{{.ImportPath}}{{end}}", "std")
+       cmd := exec.Command(testenv.GoToolPath(t), "list", "-f", "{{if .GoFiles}}{{.ImportPath}}{{end}}", "std")
        cmd.Stderr = &stderr
        out, err := cmd.Output()
        if err != nil {
index fbabc657fe847eaa6f7addf45365fc6efe81bbb8..60c35a96193bf4113687c54b503aa424122aff8d 100644 (file)
@@ -101,8 +101,8 @@ func TestPanicNilRace(t *testing.T) {
 }
 
 func TestCmdBisect(t *testing.T) {
-       testenv.MustHaveGoBuild(t)
-       out, err := exec.Command("go", "run", "cmd/vendor/golang.org/x/tools/cmd/bisect", "GODEBUG=buggy=1#PATTERN", os.Args[0], "-test.run=^TestBisectTestCase$").CombinedOutput()
+       testenv.MustHaveGoRun(t)
+       out, err := exec.Command(testenv.GoToolPath(t), "run", "cmd/vendor/golang.org/x/tools/cmd/bisect", "GODEBUG=buggy=1#PATTERN", os.Args[0], "-test.run=^TestBisectTestCase$").CombinedOutput()
        if err != nil {
                t.Fatalf("exec bisect: %v\n%s", err, out)
        }
index 3072b96ed81343133c6ab86e1225315577e00742..f5f6bb84d0ef11606cca404209aea058897552eb 100644 (file)
@@ -10,6 +10,7 @@ package wasi_test
 import (
        "bufio"
        "fmt"
+       "internal/testenv"
        "io"
        "math/rand"
        "os"
@@ -41,6 +42,8 @@ func TestNonblock(t *testing.T) {
                t.Skip("wasmer does not support non-blocking I/O")
        }
 
+       testenv.MustHaveGoRun(t)
+
        for _, mode := range []string{"os.OpenFile", "os.NewFile"} {
                t.Run(mode, func(t *testing.T) {
                        args := []string{"run", "./testdata/nonblock.go", mode}
@@ -62,7 +65,7 @@ func TestNonblock(t *testing.T) {
                                fifos[len(fifos)-i-1] = &fifo{file, path}
                        }
 
-                       subProcess := exec.Command("go", args...)
+                       subProcess := exec.Command(testenv.GoToolPath(t), args...)
 
                        subProcess.Env = append(os.Environ(), "GOOS=wasip1", "GOARCH=wasm")
 
index bbcea9031069149a82a4cdbe71a94ad0bd27fd91..aa57d9e2e340a3991898a15692bec2a5b910d427 100644 (file)
@@ -7,6 +7,7 @@ package wasi_test
 import (
        "bytes"
        "fmt"
+       "internal/testenv"
        "math/rand"
        "net"
        "os"
@@ -20,6 +21,8 @@ func TestTCPEcho(t *testing.T) {
                t.Skip()
        }
 
+       testenv.MustHaveGoRun(t)
+
        // We're unable to use port 0 here (let the OS choose a spare port).
        // Although the WASM runtime accepts port 0, and the WASM module listens
        // successfully, there's no way for this test to query the selected port
@@ -44,7 +47,7 @@ func TestTCPEcho(t *testing.T) {
                port++
        }
 
-       subProcess := exec.Command("go", "run", "./testdata/tcpecho.go")
+       subProcess := exec.Command(testenv.GoToolPath(t), "run", "./testdata/tcpecho.go")
 
        subProcess.Env = append(os.Environ(), "GOOS=wasip1", "GOARCH=wasm")