]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: run test binaries in original environment
authorRuss Cox <rsc@golang.org>
Tue, 11 Aug 2015 14:35:30 +0000 (10:35 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 11 Aug 2015 20:46:22 +0000 (20:46 +0000)
Fixes #12096.
Followup to CL 12483, which fixed #11709 and #11449.

Change-Id: I9031ea36cc60685f4d6f65c39f770c89b3e3395a
Reviewed-on: https://go-review.googlesource.com/13449
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/go/build.go
src/cmd/go/go_test.go
src/cmd/go/main.go
src/cmd/go/test.go
src/cmd/go/vcs.go

index 718edd2f77fdb1163c0d2785b5a0bee9299d53f6..b7c7e0584fc84c66a9ccc59026b4364d28779644 100644 (file)
@@ -1880,7 +1880,7 @@ func (b *builder) runOut(dir string, desc string, env []string, cmdargs ...inter
                cmd.Stdout = &buf
                cmd.Stderr = &buf
                cmd.Dir = dir
-               cmd.Env = mergeEnvLists(env, envForDir(cmd.Dir))
+               cmd.Env = mergeEnvLists(env, envForDir(cmd.Dir, os.Environ()))
                err := cmd.Run()
 
                // cmd.Run will fail on Unix if some other process has the binary
index 0718869aa66daa46a03182ed77ac7f443b3d9969..77b2628982bb81675d07d2705017aa1dd7c1efe4 100644 (file)
@@ -2294,6 +2294,21 @@ func TestIssue11709(t *testing.T) {
        tg.run("run", tg.path("run.go"))
 }
 
+func TestIssue12096(t *testing.T) {
+       tg := testgo(t)
+       defer tg.cleanup()
+       tg.tempFile("test_test.go", `
+               package main
+               import ("os"; "testing")
+               func TestEnv(t *testing.T) {
+                       if os.Getenv("TERM") != "" {
+                               t.Fatal("TERM is set")
+                       }
+               }`)
+       tg.unsetenv("TERM")
+       tg.run("test", tg.path("test_test.go"))
+}
+
 func TestGoBuildOutput(t *testing.T) {
        tg := testgo(t)
        defer tg.cleanup()
index 88a94417d74a85eabe4abb6889ed814421351e2b..8ebde8925990dc5a4ad1f19a7da298d20302fd8b 100644 (file)
@@ -446,11 +446,10 @@ func runOut(dir string, cmdargs ...interface{}) []byte {
 // The environment is the current process's environment
 // but with an updated $PWD, so that an os.Getwd in the
 // child will be faster.
-func envForDir(dir string) []string {
-       env := os.Environ()
+func envForDir(dir string, base []string) []string {
        // Internally we only use rooted paths, so dir is rooted.
        // Even if dir is not rooted, no harm done.
-       return mergeEnvLists([]string{"PWD=" + dir}, env)
+       return mergeEnvLists([]string{"PWD=" + dir}, base)
 }
 
 // mergeEnvLists merges the two environment lists such that
index 0ba18837143a2c24d96a0c927a2440c2ead7488e..ba1ab82680d9c06112d18c7b79f1d9ea9200298e 100644 (file)
@@ -1027,7 +1027,7 @@ func (b *builder) runTest(a *action) error {
 
        cmd := exec.Command(args[0], args[1:]...)
        cmd.Dir = a.p.Dir
-       cmd.Env = envForDir(cmd.Dir)
+       cmd.Env = envForDir(cmd.Dir, origEnv)
        var buf bytes.Buffer
        if testStreamOutput {
                cmd.Stdout = os.Stdout
index 2ee1057a5839cf192571532291c47b1ee54f4296..28a7540dfe43c0b14f929e94051a74eb6b1ae399 100644 (file)
@@ -344,7 +344,7 @@ func (v *vcsCmd) run1(dir string, cmdline string, keyval []string, verbose bool)
 
        cmd := exec.Command(v.cmd, args...)
        cmd.Dir = dir
-       cmd.Env = envForDir(cmd.Dir)
+       cmd.Env = envForDir(cmd.Dir, os.Environ())
        if buildX {
                fmt.Printf("cd %s\n", dir)
                fmt.Printf("%s %s\n", v.cmd, strings.Join(args, " "))