Skip to content

Commit 29e55b2

Browse files
ianlancetaylorgopherbot
authored andcommitted
unix: use os.Executable rather than os.Args[0] in tests
Change-Id: I67a063d747c6e34dcd0292fdb3a9a0d965a6e133 Reviewed-on: https://go-review.googlesource.com/c/sys/+/607875 Commit-Queue: Ian Lance Taylor <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Michael Knyszek <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]>
1 parent a8c5219 commit 29e55b2

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

Diff for: unix/darwin_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,14 @@ func TestDarwinLoader(t *testing.T) {
3535
//
3636
// In an ideal world each syscall would have its own test, so this test
3737
// would be unnecessary. Unfortunately, we do not live in that world.
38+
exe, err := os.Executable()
39+
if err != nil {
40+
t.Fatal(err)
41+
}
3842
for _, test := range darwinTests {
3943
// Call the test binary recursively, giving it a magic argument
4044
// (see init below) and the name of the test to run.
41-
cmd := exec.Command(os.Args[0], "testDarwinLoader", test.name)
45+
cmd := exec.Command(exe, "testDarwinLoader", test.name)
4246

4347
// Run subprocess, collect results. Note that we expect the subprocess
4448
// to fail somehow, so the error is irrelevant.

Diff for: unix/openbsd_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func init() {
4343
// testCmd generates a proper command that, when executed, runs the test
4444
// corresponding to the given key.
4545
func testCmd(procName string) (*exec.Cmd, error) {
46-
exe, err := filepath.Abs(os.Args[0])
46+
exe, err := os.Executable()
4747
if err != nil {
4848
return nil, err
4949
}

Diff for: unix/syscall_freebsd_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func init() {
5353
}
5454

5555
func testCmd(procName string, procArg string) (*exec.Cmd, error) {
56-
exe, err := filepath.Abs(os.Args[0])
56+
exe, err := os.Executable()
5757
if err != nil {
5858
return nil, err
5959
}

Diff for: unix/syscall_unix_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,11 @@ func TestPassFD(t *testing.T) {
205205
defer writeFile.Close()
206206
defer readFile.Close()
207207

208-
cmd := exec.Command(os.Args[0], "-test.run=^TestPassFD$", "--", t.TempDir())
208+
exe, err := os.Executable()
209+
if err != nil {
210+
t.Fatal(err)
211+
}
212+
cmd := exec.Command(exe, "-test.run=^TestPassFD$", "--", t.TempDir())
209213
cmd.Env = []string{"GO_WANT_HELPER_PROCESS=1"}
210214
if lp := os.Getenv("LD_LIBRARY_PATH"); lp != "" {
211215
cmd.Env = append(cmd.Env, "LD_LIBRARY_PATH="+lp)

0 commit comments

Comments
 (0)