]> Cypherpunks repositories - gostls13.git/commitdiff
os: don't invoke shell in TestStatStdin
authorIan Lance Taylor <iant@golang.org>
Mon, 4 Sep 2023 17:35:13 +0000 (10:35 -0700)
committerGopher Robot <gobot@golang.org>
Tue, 5 Sep 2023 22:34:26 +0000 (22:34 +0000)
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>

src/os/os_test.go

index a9de3f101414b684210907bd4322ec0d1b5a9529..c5776a9f293f56ac81eca3432dc64239224f2eac 100644 (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 {