]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/moddeps: use testenv.Command instead of exec.Command in tests
authorBryan C. Mills <bcmills@google.com>
Tue, 15 Nov 2022 15:11:08 +0000 (10:11 -0500)
committerGopher Robot <gobot@golang.org>
Tue, 15 Nov 2022 20:21:28 +0000 (20:21 +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: Ia18c323067a416381e5a70d08c50f51576054a79
Reviewed-on: https://go-review.googlesource.com/c/go/+/450698
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/internal/moddeps/moddeps_test.go

index 26673937a07e17cc401018c3eac97d44f6122d7d..41220645c6ed18d009e5d586e6ca06a88472fca1 100644 (file)
@@ -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)