From f3ae7ac9d90a26e9bba1589ae934e62bf0ac17e0 Mon Sep 17 00:00:00 2001 From: cui fliter Date: Wed, 16 Nov 2022 22:45:54 +0800 Subject: [PATCH] os: use testenv.Command instead of exec.Command in tests 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 TryBot-Result: Gopher Robot Reviewed-by: Joedian Reid Auto-Submit: Bryan Mills Run-TryBot: Bryan Mills --- src/os/executable_test.go | 4 ++-- src/os/os_test.go | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/os/executable_test.go b/src/os/executable_test.go index 719d6a61c3..b69fe41ea3 100644 --- a/src/os/executable_test.go +++ b/src/os/executable_test.go @@ -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) diff --git a/src/os/os_test.go b/src/os/os_test.go index e548777bfc..4aba265243 100644 --- a/src/os/os_test.go +++ b/src/os/os_test.go @@ -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 -- 2.50.0