From: Ian Lance Taylor Date: Mon, 4 Sep 2023 17:35:13 +0000 (-0700) Subject: os: don't invoke shell in TestStatStdin X-Git-Tag: go1.22rc1~991 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=a8191789153dcc76abb6a4d3cd4e56e2d68c2430;p=gostls13.git os: don't invoke shell in TestStatStdin Change-Id: I4048caffd4f79e3ffb6a0a3770bdfa830d1a2f35 Reviewed-on: https://go-review.googlesource.com/c/go/+/525515 Reviewed-by: Dmitri Shuralyov LUCI-TryBot-Result: Go LUCI Reviewed-by: Ian Lance Taylor Reviewed-by: Tobias Klauser Auto-Submit: Ian Lance Taylor --- diff --git a/src/os/os_test.go b/src/os/os_test.go index a9de3f1014..c5776a9f29 100644 --- a/src/os/os_test.go +++ b/src/os/os_test.go @@ -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 {