os: don't invoke shell in TestStatStdin

Change-Id: I4048caffd4f79e3ffb6a0a3770bdfa830d1a2f35
Reviewed-on: https://go-review.googlesource.com/c/go/+/525515
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
This commit is contained in:
Ian Lance Taylor 2023-09-04 10:35:13 -07:00 committed by Gopher Robot
parent 972cc3e7c2
commit a819178915
1 changed files with 10 additions and 7 deletions

View File

@ -2374,6 +2374,11 @@ func TestStatStdin(t *testing.T) {
Exit(0)
}
exe, err := Executable()
if err != nil {
t.Skipf("can't find executable: %v", err)
}
testenv.MustHaveExec(t)
t.Parallel()
@ -2388,13 +2393,11 @@ func TestStatStdin(t *testing.T) {
t.Fatalf("unexpected Stdin mode (%v), want ModeCharDevice or ModeNamedPipe", mode)
}
var cmd *exec.Cmd
if runtime.GOOS == "windows" {
cmd = testenv.Command(t, "cmd", "/c", "echo output | "+Args[0]+" -test.run=TestStatStdin")
} else {
cmd = testenv.Command(t, "/bin/sh", "-c", "echo output | "+Args[0]+" -test.run=TestStatStdin")
}
cmd.Env = append(Environ(), "GO_WANT_HELPER_PROCESS=1")
cmd := testenv.Command(t, exe, "-test.run=^TestStatStdin$")
cmd = testenv.CleanCmdEnv(cmd)
cmd.Env = append(cmd.Env, "GO_WANT_HELPER_PROCESS=1")
// This will make standard input a pipe.
cmd.Stdin = strings.NewReader("output")
output, err := cmd.CombinedOutput()
if err != nil {