From 3e45412327a2654a77944249962b3652e6142299 Mon Sep 17 00:00:00 2001 From: Ondřej Surý Date: Mon, 17 Jan 2011 12:40:45 +0100 Subject: Imported Upstream version 2011.01.12 --- src/pkg/exec/exec_test.go | 46 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) (limited to 'src/pkg/exec/exec_test.go') 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) + } +} -- cgit v1.2.3