Skip to content

Commit

Permalink
os: use testenv.Command instead of exec.Command in tests
Browse files Browse the repository at this point in the history
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 <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Joedian Reid <[email protected]>
Auto-Submit: Bryan Mills <[email protected]>
Run-TryBot: Bryan Mills <[email protected]>
  • Loading branch information
cuishuang authored and gopherbot committed Nov 17, 2022
1 parent 86713ea commit f3ae7ac
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/os/executable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions src/os/os_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f3ae7ac

Please sign in to comment.