diff options
Diffstat (limited to 'libgo/go/os/exec/exec_test.go')
-rw-r--r-- | libgo/go/os/exec/exec_test.go | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/libgo/go/os/exec/exec_test.go b/libgo/go/os/exec/exec_test.go index 32868fc..0624892 100644 --- a/libgo/go/os/exec/exec_test.go +++ b/libgo/go/os/exec/exec_test.go @@ -48,6 +48,33 @@ func TestEcho(t *testing.T) { } } +func TestCommandRelativeName(t *testing.T) { + // Run our own binary as a relative path + // (e.g. "_test/exec.test") our parent directory. + base := filepath.Base(os.Args[0]) // "exec.test" + dir := filepath.Dir(os.Args[0]) // "/tmp/go-buildNNNN/os/exec/_test" + if dir == "." { + t.Skip("skipping; running test at root somehow") + } + parentDir := filepath.Dir(dir) // "/tmp/go-buildNNNN/os/exec" + dirBase := filepath.Base(dir) // "_test" + if dirBase == "." { + t.Skipf("skipping; unexpected shallow dir of %q", dir) + } + + cmd := exec.Command(filepath.Join(dirBase, base), "-test.run=TestHelperProcess", "--", "echo", "foo") + cmd.Dir = parentDir + cmd.Env = []string{"GO_WANT_HELPER_PROCESS=1"} + + out, err := cmd.Output() + if err != nil { + t.Errorf("echo: %v", err) + } + if g, e := string(out), "foo\n"; g != e { + t.Errorf("echo: want %q, got %q", e, g) + } +} + func TestCatStdin(t *testing.T) { // Cat, testing stdin and stdout. input := "Input string\nLine 2" @@ -484,6 +511,8 @@ func TestHelperProcess(*testing.T) { switch runtime.GOOS { case "dragonfly", "freebsd", "netbsd", "openbsd": ofcmd = "fstat" + case "plan9": + ofcmd = "/bin/cat" } args := os.Args @@ -574,6 +603,14 @@ func TestHelperProcess(*testing.T) { // the cloned file descriptors that result from opening // /dev/urandom. // http://golang.org/issue/3955 + case "plan9": + // TODO(0intro): Determine why Plan 9 is leaking + // file descriptors. + // http://golang.org/issue/7118 + case "solaris": + // TODO(aram): This fails on Solaris because libc opens + // its own files, as it sees fit. Darwin does the same, + // see: http://golang.org/issue/2603 default: // Now verify that there are no other open fds. var files []*os.File @@ -585,7 +622,14 @@ func TestHelperProcess(*testing.T) { } if got := f.Fd(); got != wantfd { fmt.Printf("leaked parent file. fd = %d; want %d\n", got, wantfd) - out, _ := exec.Command(ofcmd, "-p", fmt.Sprint(os.Getpid())).CombinedOutput() + var args []string + switch runtime.GOOS { + case "plan9": + args = []string{fmt.Sprintf("/proc/%d/fd", os.Getpid())} + default: + args = []string{"-p", fmt.Sprint(os.Getpid())} + } + out, _ := exec.Command(ofcmd, args...).CombinedOutput() fmt.Print(string(out)) os.Exit(1) } |