]> Cypherpunks repositories - gostls13.git/commitdiff
os: use testenv.Command instead of exec.Command in tests
authorcui fliter <imcusg@gmail.com>
Wed, 16 Nov 2022 14:45:54 +0000 (22:45 +0800)
committerGopher Robot <gobot@golang.org>
Thu, 17 Nov 2022 16:24:19 +0000 (16:24 +0000)
testenv.Command sets a default timeout based on the test's deadline
and sends SIGQUIT (where supported) in case of a hang.

Change-Id: I32ea9ca11c30d8af3d5490f2db1674314962cc80
Reviewed-on: https://go-review.googlesource.com/c/go/+/451195
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Joedian Reid <joedian@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>

src/os/executable_test.go
src/os/os_test.go

index 719d6a61c3f6a333755be261fdeddfb85a1d38ae..b69fe41ea3401b896169c53bb9aaf9acb07093df 100644 (file)
@@ -106,13 +106,13 @@ func TestExecutableDeleted(t *testing.T) {
                t.Fatal(err)
        }
 
-       out, err := osexec.Command(testenv.GoToolPath(t), "build", "-o", exe, src).CombinedOutput()
+       out, err := testenv.Command(t, testenv.GoToolPath(t), "build", "-o", exe, src).CombinedOutput()
        t.Logf("build output:\n%s", out)
        if err != nil {
                t.Fatal(err)
        }
 
-       out, err = osexec.Command(exe).CombinedOutput()
+       out, err = testenv.Command(t, exe).CombinedOutput()
        t.Logf("exec output:\n%s", out)
        if err != nil {
                t.Fatal(err)
index e548777bfc0089658490388cabdc887973937773..4aba265243db3b8343706ecfbef8d4f140a0594f 100644 (file)
@@ -1735,7 +1735,7 @@ func runBinHostname(t *testing.T) string {
 }
 
 func testWindowsHostname(t *testing.T, hostname string) {
-       cmd := osexec.Command("hostname")
+       cmd := testenv.Command(t, "hostname")
        out, err := cmd.Output()
        if err != nil {
                t.Fatalf("Failed to execute hostname command: %v %s", err, out)
@@ -2130,9 +2130,9 @@ func TestStatStdin(t *testing.T) {
 
        var cmd *osexec.Cmd
        if runtime.GOOS == "windows" {
-               cmd = osexec.Command("cmd", "/c", "echo output | "+Args[0]+" -test.run=TestStatStdin")
+               cmd = testenv.Command(t, "cmd", "/c", "echo output | "+Args[0]+" -test.run=TestStatStdin")
        } else {
-               cmd = osexec.Command("/bin/sh", "-c", "echo output | "+Args[0]+" -test.run=TestStatStdin")
+               cmd = testenv.Command(t, "/bin/sh", "-c", "echo output | "+Args[0]+" -test.run=TestStatStdin")
        }
        cmd.Env = append(Environ(), "GO_WANT_HELPER_PROCESS=1")
 
@@ -2287,7 +2287,7 @@ func testKillProcess(t *testing.T, processKiller func(p *Process)) {
        t.Parallel()
 
        // Re-exec the test binary to start a process that hangs until stdin is closed.
-       cmd := osexec.Command(Args[0])
+       cmd := testenv.Command(t, Args[0])
        cmd.Env = append(os.Environ(), "GO_OS_TEST_DRAIN_STDIN=1")
        stdout, err := cmd.StdoutPipe()
        if err != nil {
@@ -2338,7 +2338,7 @@ func TestGetppid(t *testing.T) {
                Exit(0)
        }
 
-       cmd := osexec.Command(Args[0], "-test.run=TestGetppid")
+       cmd := testenv.Command(t, Args[0], "-test.run=TestGetppid")
        cmd.Env = append(Environ(), "GO_WANT_HELPER_PROCESS=1")
 
        // verify that Getppid() from the forked process reports our process id