diff options
author | Alex Brainman <alex.brainman@gmail.com> | 2010-11-13 11:15:09 +1100 |
---|---|---|
committer | Alex Brainman <alex.brainman@gmail.com> | 2010-11-13 11:15:09 +1100 |
commit | a2a4e0c01af416f0ca1892cefa176942ed103c16 (patch) | |
tree | 75a33d4205d9fdbc5e73edba2ac53f9e2aba7894 | |
parent | 8f651ff742a3dc69b03afa6ba6a09c5c1d47c450 (diff) | |
download | go-a2a4e0c01af416f0ca1892cefa176942ed103c16.tar.gz go-a2a4e0c01af416f0ca1892cefa176942ed103c16.zip |
exec: enable tests on windows
Fixes #1104.
R=golang-dev, mattn, r
CC=Joe Poirier, golang-dev
https://golang.org/cl/3051041
-rw-r--r-- | src/pkg/Makefile | 1 | ||||
-rw-r--r-- | src/pkg/exec/exec_test.go | 42 |
2 files changed, 17 insertions, 26 deletions
diff --git a/src/pkg/Makefile b/src/pkg/Makefile index cfb16d2004..48649846b8 100644 --- a/src/pkg/Makefile +++ b/src/pkg/Makefile @@ -197,7 +197,6 @@ endif # Disable tests that windows cannot run yet. ifeq ($(GOOS),windows) -NOTEST+=exec # no pipe NOTEST+=os/signal # no signals NOTEST+=path # tree walking does not work NOTEST+=syslog # no network diff --git a/src/pkg/exec/exec_test.go b/src/pkg/exec/exec_test.go index 04f72cf833..3a3d3b1a53 100644 --- a/src/pkg/exec/exec_test.go +++ b/src/pkg/exec/exec_test.go @@ -9,15 +9,23 @@ import ( "io/ioutil" "testing" "os" + "runtime" ) -func TestRunCat(t *testing.T) { - cat, err := LookPath("cat") +func run(argv []string, stdin, stdout, stderr int) (p *Cmd, err os.Error) { + if runtime.GOOS == "windows" { + argv = append([]string{"cmd", "/c"}, argv...) + } + exe, err := LookPath(argv[0]) if err != nil { - t.Fatal("cat: ", err) + return nil, err } - cmd, err := Run(cat, []string{"cat"}, nil, "", - Pipe, Pipe, DevNull) + p, err = Run(exe, argv, nil, "", stdin, stdout, stderr) + return p, err +} + +func TestRunCat(t *testing.T) { + cmd, err := run([]string{"cat"}, Pipe, Pipe, DevNull) if err != nil { t.Fatal("run:", err) } @@ -36,11 +44,7 @@ func TestRunCat(t *testing.T) { } func TestRunEcho(t *testing.T) { - echo, err := LookPath("echo") - if err != nil { - t.Fatal("echo: ", err) - } - cmd, err := Run(echo, []string{"echo", "hello", "world"}, nil, "", + cmd, err := run([]string{"sh", "-c", "echo hello world"}, DevNull, Pipe, DevNull) if err != nil { t.Fatal("run:", err) @@ -58,11 +62,7 @@ func TestRunEcho(t *testing.T) { } func TestStderr(t *testing.T) { - sh, err := LookPath("sh") - if err != nil { - t.Fatal("sh: ", err) - } - cmd, err := Run(sh, []string{"sh", "-c", "echo hello world 1>&2"}, nil, "", + cmd, err := run([]string{"sh", "-c", "echo hello world 1>&2"}, DevNull, DevNull, Pipe) if err != nil { t.Fatal("run:", err) @@ -80,11 +80,7 @@ func TestStderr(t *testing.T) { } func TestMergeWithStdout(t *testing.T) { - sh, err := LookPath("sh") - if err != nil { - t.Fatal("sh: ", err) - } - cmd, err := Run(sh, []string{"sh", "-c", "echo hello world 1>&2"}, nil, "", + cmd, err := run([]string{"sh", "-c", "echo hello world 1>&2"}, DevNull, Pipe, MergeWithStdout) if err != nil { t.Fatal("run:", err) @@ -106,11 +102,7 @@ func TestAddEnvVar(t *testing.T) { if err != nil { t.Fatal("setenv:", err) } - sh, err := LookPath("sh") - if err != nil { - t.Fatal("sh: ", err) - } - cmd, err := Run(sh, []string{"sh", "-c", "echo $NEWVAR"}, nil, "", + cmd, err := run([]string{"sh", "-c", "echo $NEWVAR"}, DevNull, Pipe, DevNull) if err != nil { t.Fatal("run:", err) |