aboutsummaryrefslogtreecommitdiff
path: root/src/os/exec/exec_test.go
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2019-10-17 09:45:54 -0400
committerBryan C. Mills <bcmills@google.com>2019-10-17 15:04:49 +0000
commit00ea8e1c673eb2b72c4520c688a414831e871ad2 (patch)
tree70182c71d68b9412ae149f0b0d379cdc87274103 /src/os/exec/exec_test.go
parent86235ec2bf15ff90c4c6602063c40c9bf0325428 (diff)
downloadgo-00ea8e1c673eb2b72c4520c688a414831e871ad2.tar.gz
go-00ea8e1c673eb2b72c4520c688a414831e871ad2.zip
os/exec: preserve the process environment when invoking TestHelperProcess
Also log errors from the lsof command on failure. (That's how the missing environment was discovered.) Updates #25628 Change-Id: I71594f60c15d0d254d5d4a86deec7431314c92ff Reviewed-on: https://go-review.googlesource.com/c/go/+/201717 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/os/exec/exec_test.go')
-rw-r--r--src/os/exec/exec_test.go12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/os/exec/exec_test.go b/src/os/exec/exec_test.go
index c9322f6b0f..41ffb60e6e 100644
--- a/src/os/exec/exec_test.go
+++ b/src/os/exec/exec_test.go
@@ -40,7 +40,7 @@ func helperCommandContext(t *testing.T, ctx context.Context, s ...string) (cmd *
} else {
cmd = exec.Command(os.Args[0], cs...)
}
- cmd.Env = []string{"GO_WANT_HELPER_PROCESS=1"}
+ cmd.Env = append(os.Environ(), "GO_WANT_HELPER_PROCESS=1")
return cmd
}
@@ -656,7 +656,7 @@ func TestExtraFiles(t *testing.T) {
c.ExtraFiles = []*os.File{tf}
err = c.Run()
if err != nil {
- t.Fatalf("Run: %v; stdout %q, stderr %q", err, stdout.Bytes(), stderr.Bytes())
+ t.Fatalf("Run: %v\n--- stdout:\n%s--- stderr:\n%s", err, stdout.Bytes(), stderr.Bytes())
}
if stdout.String() != text {
t.Errorf("got stdout %q, stderr %q; want %q on stdout", stdout.String(), stderr.String(), text)
@@ -861,8 +861,12 @@ func TestHelperProcess(*testing.T) {
default:
args = []string{"-p", fmt.Sprint(os.Getpid())}
}
- out, _ := exec.Command(ofcmd, args...).CombinedOutput()
- fmt.Print(string(out))
+ cmd := exec.Command(ofcmd, args...)
+ out, err := cmd.CombinedOutput()
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "%s failed: %v\n", strings.Join(cmd.Args, " "), err)
+ }
+ fmt.Printf("%s", out)
os.Exit(1)
}
files = append(files, f)