summaryrefslogtreecommitdiff
path: root/src/pkg/exec/exec_test.go
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2011-01-17 12:40:45 +0100
committerOndřej Surý <ondrej@sury.org>2011-01-17 12:40:45 +0100
commit3e45412327a2654a77944249962b3652e6142299 (patch)
treebc3bf69452afa055423cbe0c5cfa8ca357df6ccf /src/pkg/exec/exec_test.go
parentc533680039762cacbc37db8dc7eed074c3e497be (diff)
downloadgolang-upstream/2011.01.12.tar.gz
Imported Upstream version 2011.01.12upstream/2011.01.12
Diffstat (limited to 'src/pkg/exec/exec_test.go')
-rw-r--r--src/pkg/exec/exec_test.go46
1 files changed, 40 insertions, 6 deletions
diff --git a/src/pkg/exec/exec_test.go b/src/pkg/exec/exec_test.go
index 3e4ab7d78..3a3d3b1a5 100644
--- a/src/pkg/exec/exec_test.go
+++ b/src/pkg/exec/exec_test.go
@@ -8,11 +8,24 @@ import (
"io"
"io/ioutil"
"testing"
+ "os"
+ "runtime"
)
+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 {
+ return nil, err
+ }
+ p, err = Run(exe, argv, nil, "", stdin, stdout, stderr)
+ return p, err
+}
+
func TestRunCat(t *testing.T) {
- cmd, err := Run("/bin/cat", []string{"cat"}, nil, "",
- Pipe, Pipe, DevNull)
+ cmd, err := run([]string{"cat"}, Pipe, Pipe, DevNull)
if err != nil {
t.Fatal("run:", err)
}
@@ -31,7 +44,7 @@ func TestRunCat(t *testing.T) {
}
func TestRunEcho(t *testing.T) {
- cmd, err := Run("/bin/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)
@@ -49,7 +62,7 @@ func TestRunEcho(t *testing.T) {
}
func TestStderr(t *testing.T) {
- cmd, err := Run("/bin/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)
@@ -66,9 +79,8 @@ func TestStderr(t *testing.T) {
}
}
-
func TestMergeWithStdout(t *testing.T) {
- cmd, err := Run("/bin/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)
@@ -84,3 +96,25 @@ func TestMergeWithStdout(t *testing.T) {
t.Fatal("close:", err)
}
}
+
+func TestAddEnvVar(t *testing.T) {
+ err := os.Setenv("NEWVAR", "hello world")
+ if err != nil {
+ t.Fatal("setenv:", err)
+ }
+ cmd, err := run([]string{"sh", "-c", "echo $NEWVAR"},
+ DevNull, Pipe, DevNull)
+ if err != nil {
+ t.Fatal("run:", err)
+ }
+ buf, err := ioutil.ReadAll(cmd.Stdout)
+ if err != nil {
+ t.Fatal("read:", err)
+ }
+ if string(buf) != "hello world\n" {
+ t.Fatalf("read: got %q", buf)
+ }
+ if err = cmd.Close(); err != nil {
+ t.Fatal("close:", err)
+ }
+}