aboutsummaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
authorqmuntal <quimmuntal@gmail.com>2025-02-24 09:43:41 +0100
committerQuim Muntal <quimmuntal@gmail.com>2025-02-24 11:03:10 -0800
commitdceee2e983f5dab65c3905ecf40e70e15cf41b7d (patch)
tree90d8aec778115127028196a5de6b321008252b92 /src/cmd
parent2ee775fd9b58247618cf8bc06935f33875bdc872 (diff)
downloadgo-dceee2e983f5dab65c3905ecf40e70e15cf41b7d.tar.xz
all: use testenv.Executable instead of os.Executable and os.Args[0]
In test files, using testenv.Executable is more reliable than os.Executable or os.Args[0]. Change-Id: I88e577efeabc20d02ada27bf706ae4523129128e Reviewed-on: https://go-review.googlesource.com/c/go/+/651955 Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/cgo/internal/test/issue18146.go5
-rw-r--r--src/cmd/go/internal/lockedfile/internal/filelock/filelock_test.go2
-rw-r--r--src/cmd/go/internal/lockedfile/lockedfile_test.go4
3 files changed, 5 insertions, 6 deletions
diff --git a/src/cmd/cgo/internal/test/issue18146.go b/src/cmd/cgo/internal/test/issue18146.go
index 112b7ee2e7..04e5b5ffb8 100644
--- a/src/cmd/cgo/internal/test/issue18146.go
+++ b/src/cmd/cgo/internal/test/issue18146.go
@@ -11,6 +11,7 @@ package cgotest
import (
"bytes"
"crypto/md5"
+ "internal/testenv"
"os"
"os/exec"
"runtime"
@@ -73,7 +74,7 @@ func test18146(t *testing.T) {
}
runtime.GOMAXPROCS(threads)
argv := append(os.Args, "-test.run=^$")
- if err := syscall.Exec(os.Args[0], argv, os.Environ()); err != nil {
+ if err := syscall.Exec(testenv.Executable(t), argv, os.Environ()); err != nil {
t.Fatal(err)
}
}
@@ -87,7 +88,7 @@ func test18146(t *testing.T) {
args := append(append([]string(nil), os.Args[1:]...), "-test.run=^Test18146$")
for n := attempts; n > 0; n-- {
- cmd := exec.Command(os.Args[0], args...)
+ cmd := exec.Command(testenv.Executable(t), args...)
cmd.Env = append(os.Environ(), "test18146=exec")
buf := bytes.NewBuffer(nil)
cmd.Stdout = buf
diff --git a/src/cmd/go/internal/lockedfile/internal/filelock/filelock_test.go b/src/cmd/go/internal/lockedfile/internal/filelock/filelock_test.go
index 035840db7e..c1423e6087 100644
--- a/src/cmd/go/internal/lockedfile/internal/filelock/filelock_test.go
+++ b/src/cmd/go/internal/lockedfile/internal/filelock/filelock_test.go
@@ -198,7 +198,7 @@ func TestLockNotDroppedByExecCommand(t *testing.T) {
// Some kinds of file locks are dropped when a duplicated or forked file
// descriptor is unlocked. Double-check that the approach used by os/exec does
// not accidentally drop locks.
- cmd := testenv.Command(t, os.Args[0], "-test.run=^$")
+ cmd := testenv.Command(t, testenv.Executable(t), "-test.run=^$")
if err := cmd.Run(); err != nil {
t.Fatalf("exec failed: %v", err)
}
diff --git a/src/cmd/go/internal/lockedfile/lockedfile_test.go b/src/cmd/go/internal/lockedfile/lockedfile_test.go
index 8cea197abc..514d0a316c 100644
--- a/src/cmd/go/internal/lockedfile/lockedfile_test.go
+++ b/src/cmd/go/internal/lockedfile/lockedfile_test.go
@@ -180,8 +180,6 @@ func TestSpuriousEDEADLK(t *testing.T) {
// P.2 unblocks and locks file B.
// P.2 unlocks file B.
- testenv.MustHaveExec(t)
-
dirVar := t.Name() + "DIR"
if dir := os.Getenv(dirVar); dir != "" {
@@ -216,7 +214,7 @@ func TestSpuriousEDEADLK(t *testing.T) {
t.Fatal(err)
}
- cmd := testenv.Command(t, os.Args[0], "-test.run=^"+t.Name()+"$")
+ cmd := testenv.Command(t, testenv.Executable(t), "-test.run=^"+t.Name()+"$")
cmd.Env = append(os.Environ(), fmt.Sprintf("%s=%s", dirVar, dir))
qDone := make(chan struct{})