mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
os: fix ForkExec() handling of envv == nil
R=golang-dev, r CC=golang-dev https://golang.org/cl/1913047
This commit is contained in:
parent
893fdbbe5d
commit
dbef0711d4
2 changed files with 26 additions and 0 deletions
|
|
@ -8,6 +8,7 @@ import (
|
|||
"io"
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
"os"
|
||||
)
|
||||
|
||||
func TestRunCat(t *testing.T) {
|
||||
|
|
@ -84,3 +85,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("/bin/sh", []string{"sh", "-c", "echo $NEWVAR"}, nil, "",
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue