From dceee2e983f5dab65c3905ecf40e70e15cf41b7d Mon Sep 17 00:00:00 2001 From: qmuntal Date: Mon, 24 Feb 2025 09:43:41 +0100 Subject: 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 LUCI-TryBot-Result: Go LUCI Reviewed-by: Ian Lance Taylor --- src/syscall/exec_unix_test.go | 3 +-- src/syscall/exec_windows_test.go | 5 +++-- src/syscall/syscall_unix_test.go | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/syscall') diff --git a/src/syscall/exec_unix_test.go b/src/syscall/exec_unix_test.go index fda9019e39..3a95356c1e 100644 --- a/src/syscall/exec_unix_test.go +++ b/src/syscall/exec_unix_test.go @@ -302,8 +302,7 @@ func TestInvalidExec(t *testing.T) { // TestExec is for issue #41702. func TestExec(t *testing.T) { - testenv.MustHaveExec(t) - cmd := exec.Command(os.Args[0], "-test.run=^TestExecHelper$") + cmd := exec.Command(testenv.Executable(t), "-test.run=^TestExecHelper$") cmd.Env = append(os.Environ(), "GO_WANT_HELPER_PROCESS=2") o, err := cmd.CombinedOutput() if err != nil { diff --git a/src/syscall/exec_windows_test.go b/src/syscall/exec_windows_test.go index 5cacf42b6b..90a13af8d1 100644 --- a/src/syscall/exec_windows_test.go +++ b/src/syscall/exec_windows_test.go @@ -6,6 +6,7 @@ package syscall_test import ( "fmt" + "internal/testenv" "os" "os/exec" "path/filepath" @@ -73,7 +74,7 @@ func TestChangingProcessParent(t *testing.T) { // run parent process - parent := exec.Command(os.Args[0], "-test.run=^TestChangingProcessParent$") + parent := exec.Command(testenv.Executable(t), "-test.run=^TestChangingProcessParent$") parent.Env = append(os.Environ(), "GO_WANT_HELPER_PROCESS=parent") err := parent.Start() if err != nil { @@ -96,7 +97,7 @@ func TestChangingProcessParent(t *testing.T) { } defer syscall.CloseHandle(ph) - child := exec.Command(os.Args[0], "-test.run=^TestChangingProcessParent$") + child := exec.Command(testenv.Executable(t), "-test.run=^TestChangingProcessParent$") child.Env = append(os.Environ(), "GO_WANT_HELPER_PROCESS=child", "GO_WANT_HELPER_PROCESS_FILE="+childDumpPath) diff --git a/src/syscall/syscall_unix_test.go b/src/syscall/syscall_unix_test.go index 56e771e086..8c6de43231 100644 --- a/src/syscall/syscall_unix_test.go +++ b/src/syscall/syscall_unix_test.go @@ -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} -- cgit v1.3