diff options
author | Yasuhiro Matsumoto <mattn.jp@gmail.com> | 2010-10-20 09:46:24 +1100 |
---|---|---|
committer | Alex Brainman <alex.brainman@gmail.com> | 2010-10-20 09:46:24 +1100 |
commit | a9725396c00b876a9e59d3b35e71c7bde7b19e70 (patch) | |
tree | 6707074fb85797ae9c68d379eba44a8a8492e531 | |
parent | a3bcf4b6640450ab249cbd4e074a05c274812bc7 (diff) | |
download | go-a9725396c00b876a9e59d3b35e71c7bde7b19e70.tar.gz go-a9725396c00b876a9e59d3b35e71c7bde7b19e70.zip |
os: change TestForkExec so it can run on windows
R=brainman, vcc, Joe Poirier, rsc
CC=golang-dev
https://golang.org/cl/2530041
-rw-r--r-- | src/pkg/os/os_test.go | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/pkg/os/os_test.go b/src/pkg/os/os_test.go index 5a4e1a865f..9cc2eb54a5 100644 --- a/src/pkg/os/os_test.go +++ b/src/pkg/os/os_test.go @@ -410,15 +410,24 @@ func TestRename(t *testing.T) { } func TestForkExec(t *testing.T) { - // TODO(brainman): Try to enable this test once ForkExec is working. - if syscall.OS == "windows" { - return - } + var cmd, adir, expect string + var args []string r, w, err := Pipe() if err != nil { t.Fatalf("Pipe: %v", err) } - pid, err := ForkExec("/bin/pwd", []string{"pwd"}, nil, "/", []*File{nil, w, Stderr}) + if syscall.OS == "windows" { + cmd = Getenv("COMSPEC") + args = []string{Getenv("COMSPEC"), "/c cd"} + adir = Getenv("SystemRoot") + expect = Getenv("SystemRoot") + "\r\n" + } else { + cmd = "/bin/pwd" + args = []string{"pwd"} + adir = "/" + expect = "/\n" + } + pid, err := ForkExec(cmd, args, nil, adir, []*File{nil, w, Stderr}) if err != nil { t.Fatalf("ForkExec: %v", err) } @@ -427,9 +436,9 @@ func TestForkExec(t *testing.T) { var b bytes.Buffer io.Copy(&b, r) output := b.String() - expect := "/\n" if output != expect { - t.Errorf("exec /bin/pwd returned %q wanted %q", output, expect) + args[0] = cmd + t.Errorf("exec %q returned %q wanted %q", strings.Join(args, " "), output, expect) } Wait(pid, 0) } |