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>
This commit is contained in:
qmuntal 2025-02-24 09:43:41 +01:00 committed by Quim Muntal
parent 2ee775fd9b
commit dceee2e983
29 changed files with 49 additions and 75 deletions

View file

@ -99,7 +99,7 @@ func TestFcntlFlock(t *testing.T) {
t.Fatalf("FcntlFlock(F_SETLK) failed: %v", err)
}
cmd := exec.Command(os.Args[0], "-test.run=^TestFcntlFlock$")
cmd := exec.Command(testenv.Executable(t), "-test.run=^TestFcntlFlock$")
cmd.Env = append(os.Environ(), "GO_WANT_HELPER_PROCESS=1")
cmd.ExtraFiles = []*os.File{f}
out, err := cmd.CombinedOutput()
@ -171,7 +171,7 @@ func TestPassFD(t *testing.T) {
defer writeFile.Close()
defer readFile.Close()
cmd := exec.Command(os.Args[0], "-test.run=^TestPassFD$", "--", tempDir)
cmd := exec.Command(testenv.Executable(t), "-test.run=^TestPassFD$", "--", tempDir)
cmd.Env = append(os.Environ(), "GO_WANT_HELPER_PROCESS=1")
cmd.ExtraFiles = []*os.File{writeFile}