mirror of
https://github.com/golang/go
synced 2024-11-26 14:56:47 -07:00
cmd/go: pass an unmodified environment to a go run program
Fixes #11709. Fixed #11449. Change-Id: If8fdb27d3dc25fb7017226d143a29cbebc1374c5 Reviewed-on: https://go-review.googlesource.com/12483 Reviewed-by: David Crawshaw <crawshaw@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
0505dfc637
commit
419a6c0709
@ -402,7 +402,7 @@ func (g *Generator) exec(words []string) {
|
||||
"GOFILE=" + g.file,
|
||||
"GOPACKAGE=" + g.pkg,
|
||||
}
|
||||
cmd.Env = mergeEnvLists(env, os.Environ())
|
||||
cmd.Env = mergeEnvLists(env, origEnv)
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
g.errorf("running %q: %s", words[0], err)
|
||||
|
@ -2229,3 +2229,18 @@ func TestGoInstallShadowedGOPATH(t *testing.T) {
|
||||
tg.runFail("install")
|
||||
tg.grepStderr("no install location for.*gopath2.src.test: hidden by .*gopath1.src.test", "missing error")
|
||||
}
|
||||
|
||||
func TestIssue11709(t *testing.T) {
|
||||
tg := testgo(t)
|
||||
defer tg.cleanup()
|
||||
tg.tempFile("run.go", `
|
||||
package main
|
||||
import "os"
|
||||
func main() {
|
||||
if os.Getenv("TERM") != "" {
|
||||
os.Exit(1)
|
||||
}
|
||||
}`)
|
||||
tg.unsetenv("TERM")
|
||||
tg.run("run", tg.path("run.go"))
|
||||
}
|
||||
|
@ -112,6 +112,8 @@ func setExitStatus(n int) {
|
||||
exitMu.Unlock()
|
||||
}
|
||||
|
||||
var origEnv []string
|
||||
|
||||
func main() {
|
||||
_ = go11tag
|
||||
flag.Usage = usage
|
||||
@ -159,6 +161,7 @@ func main() {
|
||||
// the same default computation of these as we do,
|
||||
// but in practice there might be skew
|
||||
// This makes sure we all agree.
|
||||
origEnv = os.Environ()
|
||||
for _, env := range mkEnv() {
|
||||
if os.Getenv(env.name) != env.value {
|
||||
os.Setenv(env.name, env.value)
|
||||
|
@ -137,6 +137,7 @@ func runStdin(cmdline []string) {
|
||||
cmd.Stdin = os.Stdin
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Env = origEnv
|
||||
startSigHandlers()
|
||||
if err := cmd.Run(); err != nil {
|
||||
errorf("%v", err)
|
||||
|
Loading…
Reference in New Issue
Block a user