]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/dist: use goTest for manual go test invocations
authorAustin Clements <austin@google.com>
Wed, 2 Nov 2022 18:33:04 +0000 (14:33 -0400)
committerAustin Clements <austin@google.com>
Wed, 16 Nov 2022 21:35:19 +0000 (21:35 +0000)
This CL rewrites everywhere in dist that manually constructs an
exec.Cmd to run "go test" to use the goTest abstraction. All remaining
invocations of "go test" after this CL construct the command line
manually, but ultimately use addCmd to execute it.

I traced all exec calls from cmd/dist on linux/amd64 and this makes
only no-op changes (such as re-arranging the order of flags).

For #37486.

Change-Id: Idc7497e39bac04def7ddaf2010881c9623e76fd4
Reviewed-on: https://go-review.googlesource.com/c/go/+/450015
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Austin Clements <austin@google.com>

src/cmd/dist/test.go

index 4cc125fefda1dbeb0aec71173a9e3ec0f4a88862..094c36918989917b396aa3c02b6ea2466603836b 100644 (file)
@@ -550,39 +550,18 @@ func (t *tester) registerStdTest(pkg string) {
                        defer timelog("end", dt.name)
                        ranGoTest = true
 
-                       timeoutSec := 180
+                       timeoutSec := 180 * time.Second
                        for _, pkg := range stdMatches {
                                if pkg == "cmd/go" {
                                        timeoutSec *= 3
                                        break
                                }
                        }
-                       args := []string{
-                               "test",
-                               "-short=" + short(),
-                               t.tags(),
-                               t.timeout(timeoutSec),
-                       }
-                       if gcflags != "" {
-                               args = append(args, "-gcflags=all="+gcflags)
-                       }
-                       if t.race {
-                               args = append(args, "-race")
-                       }
-                       if t.msan {
-                               args = append(args, "-msan")
-                       }
-                       if t.asan {
-                               args = append(args, "-asan")
-                       }
-                       if t.compileOnly {
-                               args = append(args, "-run=^$")
-                       }
-                       args = append(args, stdMatches...)
-                       cmd := exec.Command(gorootBinGo, args...)
-                       cmd.Stdout = os.Stdout
-                       cmd.Stderr = os.Stderr
-                       return cmd.Run()
+                       return (&goTest{
+                               timeout: timeoutSec,
+                               gcflags: gcflags,
+                               pkgs:    stdMatches,
+                       }).run(t)
                },
        })
 }
@@ -603,23 +582,13 @@ func (t *tester) registerRaceBenchTest(pkg string) {
                        timelog("start", dt.name)
                        defer timelog("end", dt.name)
                        ranGoBench = true
-                       args := []string{
-                               "test",
-                               "-short=" + short(),
-                               "-race",
-                               t.timeout(1200), // longer timeout for race with benchmarks
-                               "-run=^$",       // nothing. only benchmarks.
-                               "-benchtime=.1s",
-                               "-cpu=4",
-                       }
-                       if !t.compileOnly {
-                               args = append(args, "-bench=.*")
-                       }
-                       args = append(args, benchMatches...)
-                       cmd := exec.Command(gorootBinGo, args...)
-                       cmd.Stdout = os.Stdout
-                       cmd.Stderr = os.Stderr
-                       return cmd.Run()
+                       return (&goTest{
+                               timeout: 1200 * time.Second, // longer timeout for race with benchmarks
+                               race:    true,
+                               bench:   true,
+                               cpu:     "4",
+                               pkgs:    benchMatches,
+                       }).run(t)
                },
        })
 }
@@ -789,9 +758,10 @@ func (t *tester) registerTests() {
 
                                // Run `go test fmt` in the moved GOROOT, without explicitly setting
                                // GOROOT in the environment. The 'go' command should find itself.
-                               cmd := exec.Command(filepath.Join(moved, "bin", "go"), "test", "fmt")
-                               cmd.Stdout = os.Stdout
-                               cmd.Stderr = os.Stderr
+                               cmd := (&goTest{
+                                       goroot: moved,
+                                       pkg:    "fmt",
+                               }).command(t)
                                unsetEnv(cmd, "GOROOT")
                                unsetEnv(cmd, "GOCACHE") // TODO(bcmills): ...why‽
                                err := cmd.Run()