From 6484e813b5ec80a399ed1b8e4608070db2144b39 Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Tue, 15 Nov 2022 10:11:08 -0500 Subject: [PATCH] cmd/internal/moddeps: 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: Ia18c323067a416381e5a70d08c50f51576054a79 Reviewed-on: https://go-review.googlesource.com/c/go/+/450698 Reviewed-by: Ian Lance Taylor Auto-Submit: Bryan Mills Run-TryBot: Bryan Mills TryBot-Result: Gopher Robot --- src/cmd/internal/moddeps/moddeps_test.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/cmd/internal/moddeps/moddeps_test.go b/src/cmd/internal/moddeps/moddeps_test.go index 26673937a0..41220645c6 100644 --- a/src/cmd/internal/moddeps/moddeps_test.go +++ b/src/cmd/internal/moddeps/moddeps_test.go @@ -12,7 +12,6 @@ import ( "io" "io/fs" "os" - "os/exec" "path/filepath" "strings" "sync" @@ -53,7 +52,7 @@ func TestAllDependencies(t *testing.T) { // Load all of the packages in the module to ensure that their // dependencies are vendored. If any imported package is missing, // 'go list -deps' will fail when attempting to load it. - cmd := exec.Command(goBin, "list", "-mod=vendor", "-deps", "./...") + cmd := testenv.Command(t, goBin, "list", "-mod=vendor", "-deps", "./...") cmd.Env = append(os.Environ(), "GO111MODULE=on", "GOWORK=off") cmd.Dir = m.Dir cmd.Stderr = new(strings.Builder) @@ -67,7 +66,7 @@ func TestAllDependencies(t *testing.T) { // There is no vendor directory, so the module must have no dependencies. // Check that the list of active modules contains only the main module. - cmd := exec.Command(goBin, "list", "-mod=readonly", "-m", "all") + cmd := testenv.Command(t, goBin, "list", "-mod=readonly", "-m", "all") cmd.Env = append(os.Environ(), "GO111MODULE=on", "GOWORK=off") cmd.Dir = m.Dir cmd.Stderr = new(strings.Builder) @@ -105,11 +104,11 @@ func TestAllDependencies(t *testing.T) { testenv.MustHaveExternalNetwork(t) if haveDiff := func() bool { - diff, err := exec.Command("diff", "--recursive", "--unified", ".", ".").CombinedOutput() + diff, err := testenv.Command(t, "diff", "--recursive", "--unified", ".", ".").CombinedOutput() if err != nil || len(diff) != 0 { return false } - diff, err = exec.Command("diff", "--recursive", "--unified", ".", "..").CombinedOutput() + diff, err = testenv.Command(t, "diff", "--recursive", "--unified", ".", "..").CombinedOutput() if err == nil || len(diff) == 0 { return false } @@ -129,7 +128,7 @@ func TestAllDependencies(t *testing.T) { // GO_TEST_SHORT=0 causes it to run this portion of the test.) var modcacheEnv []string { - out, err := exec.Command(goBin, "env", "GOMODCACHE").Output() + out, err := testenv.Command(t, goBin, "env", "GOMODCACHE").Output() if err != nil { t.Fatalf("%s env GOMODCACHE: %v", goBin, err) } @@ -215,7 +214,7 @@ func TestAllDependencies(t *testing.T) { } // TODO(golang.org/issue/43440): Check anything else influenced by dependency versions. - diff, err := exec.Command("diff", "--recursive", "--unified", r.Dir, m.Dir).CombinedOutput() + diff, err := testenv.Command(t, "diff", "--recursive", "--unified", r.Dir, m.Dir).CombinedOutput() if err != nil || len(diff) != 0 { t.Errorf(`Module %s in %s is not tidy (-want +got): @@ -321,7 +320,7 @@ type runner struct { // run runs the command and requires that it succeeds. func (r runner) run(t *testing.T, args ...string) { t.Helper() - cmd := exec.Command(args[0], args[1:]...) + cmd := testenv.Command(t, args[0], args[1:]...) cmd.Dir = r.Dir cmd.Env = r.Env out, err := cmd.CombinedOutput() @@ -462,7 +461,7 @@ func findGorootModules(t *testing.T) []gorootModule { // Use 'go list' to describe the module contained in this directory (but // not its dependencies). - cmd := exec.Command(goBin, "list", "-json", "-m") + cmd := testenv.Command(t, goBin, "list", "-json", "-m") cmd.Env = append(os.Environ(), "GO111MODULE=on", "GOWORK=off") cmd.Dir = dir cmd.Stderr = new(strings.Builder) -- 2.50.0