cmd/dist: use goTest for manual go test invocations

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>
This commit is contained in:
Austin Clements 2022-11-02 14:33:04 -04:00
parent c3a0854e31
commit 2946c887ba
1 changed files with 17 additions and 47 deletions

64
src/cmd/dist/test.go vendored
View File

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