From: Austin Clements Date: Wed, 2 Nov 2022 18:33:04 +0000 (-0400) Subject: cmd/dist: use goTest for manual go test invocations X-Git-Tag: go1.20rc1~213 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=2946c887babdafd8e92550723d5bd0aeb5613335;p=gostls13.git 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 TryBot-Result: Gopher Robot Reviewed-by: Dmitri Shuralyov Run-TryBot: Austin Clements --- diff --git a/src/cmd/dist/test.go b/src/cmd/dist/test.go index 4cc125fefd..094c369189 100644 --- a/src/cmd/dist/test.go +++ b/src/cmd/dist/test.go @@ -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()