aboutsummaryrefslogtreecommitdiff
path: root/src/os/exec/exec_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/os/exec/exec_test.go')
-rw-r--r--src/os/exec/exec_test.go20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/os/exec/exec_test.go b/src/os/exec/exec_test.go
index 73aa35f1ae..f90066cea3 100644
--- a/src/os/exec/exec_test.go
+++ b/src/os/exec/exec_test.go
@@ -57,12 +57,20 @@ func init() {
func helperCommandContext(t *testing.T, ctx context.Context, s ...string) (cmd *exec.Cmd) {
testenv.MustHaveExec(t)
+ // Use os.Executable instead of os.Args[0] in case the caller modifies
+ // cmd.Dir: if the test binary is invoked like "./exec.test", it should
+ // not fail spuriously.
+ exe, err := os.Executable()
+ if err != nil {
+ t.Fatal(err)
+ }
+
cs := []string{"-test.run=TestHelperProcess", "--"}
cs = append(cs, s...)
if ctx != nil {
- cmd = exec.CommandContext(ctx, os.Args[0], cs...)
+ cmd = exec.CommandContext(ctx, exe, cs...)
} else {
- cmd = exec.Command(os.Args[0], cs...)
+ cmd = exec.Command(exe, cs...)
}
cmd.Env = append(os.Environ(), "GO_WANT_HELPER_PROCESS=1")
return cmd
@@ -831,6 +839,14 @@ func TestHelperProcess(*testing.T) {
}
pipe.Close()
os.Exit(0)
+ case "pwd":
+ pwd, err := os.Getwd()
+ if err != nil {
+ fmt.Fprintln(os.Stderr, err)
+ os.Exit(1)
+ }
+ fmt.Println(pwd)
+ os.Exit(0)
default:
fmt.Fprintf(os.Stderr, "Unknown command %q\n", cmd)
os.Exit(2)