]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/envcmd: on unix pass script contents directly to sh -c
authorMichael Matloob <matloob@golang.org>
Mon, 8 May 2023 16:53:37 +0000 (12:53 -0400)
committerMichael Matloob <matloob@golang.org>
Mon, 8 May 2023 17:34:42 +0000 (17:34 +0000)
Instead of writing them to a file and executing that file.

For #59998

Change-Id: I341786926762359f67dccb475295afbbb8ed1054
Reviewed-on: https://go-review.googlesource.com/c/go/+/493555
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
src/cmd/go/internal/envcmd/env_test.go

index 32d99fd1d1fc5170e5cb1a89be462353737d9009..7419cf3fc20e73db8b565991566e4452edf9d3d4 100644 (file)
@@ -69,16 +69,15 @@ func FuzzPrintEnvEscape(f *testing.F) {
                if runtime.GOOS == "windows" {
                        scriptfilename = "script.bat"
                }
-               scriptfile := filepath.Join(t.TempDir(), scriptfilename)
-               if err := os.WriteFile(scriptfile, b.Bytes(), 0777); err != nil {
-                       t.Fatal(err)
-               }
-               t.Log(b.String())
                var cmd *exec.Cmd
                if runtime.GOOS == "windows" {
+                       scriptfile := filepath.Join(t.TempDir(), scriptfilename)
+                       if err := os.WriteFile(scriptfile, b.Bytes(), 0777); err != nil {
+                               t.Fatal(err)
+                       }
                        cmd = testenv.Command(t, "cmd.exe", "/C", scriptfile)
                } else {
-                       cmd = testenv.Command(t, "sh", "-c", scriptfile)
+                       cmd = testenv.Command(t, "sh", "-c", b.String())
                }
                out, err := cmd.Output()
                t.Log(string(out))