Skip to content

Commit 20b4987

Browse files
committed
cmd/dist: use GO_TEST_SHORT value more consistently
There were two places where the -short flag was added in order to speed up tests when run in short mode, in CL 178399 and CL 177417. It appears viable to re-use the GO_TEST_SHORT value so that -short flag is not used when the tests are executed on a longtest builder, where it is not a goal to skip slow tests for improved performance. Do so, in order to make the testing configurations simpler and more predictable. Factor out the flag name out of the string returned by short, so that it can be used in context of 'go test' which can accept a -short flag, and a test binary which requires the use of a longer -test.short flag. For #39054. For #29252. Change-Id: I52dfbef73cc8307735c52e2ebaa609305fb05933 Reviewed-on: https://go-review.googlesource.com/c/go/+/233898 Run-TryBot: Dmitri Shuralyov <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent b58d297 commit 20b4987

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/cmd/dist/test.go

+13-11
Original file line numberDiff line numberDiff line change
@@ -241,32 +241,34 @@ func (t *tester) shouldRunTest(name string) bool {
241241
return false
242242
}
243243

244-
// short returns a -short flag to pass to 'go test'.
245-
// It returns "-short", unless the environment variable
244+
// short returns a -short flag value to use with 'go test'
245+
// or a test binary for tests intended to run in short mode.
246+
// It returns "true", unless the environment variable
246247
// GO_TEST_SHORT is set to a non-empty, false-ish string.
247248
//
248249
// This environment variable is meant to be an internal
249-
// detail between the Go build system and cmd/dist
250-
// and is not intended for use by users.
250+
// detail between the Go build system and cmd/dist for
251+
// the purpose of longtest builders, and is not intended
252+
// for use by users. See golang.org/issue/12508.
251253
func short() string {
252254
if v := os.Getenv("GO_TEST_SHORT"); v != "" {
253255
short, err := strconv.ParseBool(v)
254256
if err != nil {
255257
fatalf("invalid GO_TEST_SHORT %q: %v", v, err)
256258
}
257259
if !short {
258-
return "-short=false"
260+
return "false"
259261
}
260262
}
261-
return "-short"
263+
return "true"
262264
}
263265

264266
// goTest returns the beginning of the go test command line.
265267
// Callers should use goTest and then pass flags overriding these
266268
// defaults as later arguments in the command line.
267269
func (t *tester) goTest() []string {
268270
return []string{
269-
"go", "test", short(), "-count=1", t.tags(), t.runFlag(""),
271+
"go", "test", "-short=" + short(), "-count=1", t.tags(), t.runFlag(""),
270272
}
271273
}
272274

@@ -335,7 +337,7 @@ func (t *tester) registerStdTest(pkg string) {
335337
}
336338
args := []string{
337339
"test",
338-
short(),
340+
"-short=" + short(),
339341
t.tags(),
340342
t.timeout(timeoutSec),
341343
"-gcflags=all=" + gogcflags,
@@ -373,7 +375,7 @@ func (t *tester) registerRaceBenchTest(pkg string) {
373375
ranGoBench = true
374376
args := []string{
375377
"test",
376-
short(),
378+
"-short=" + short(),
377379
"-race",
378380
t.timeout(1200), // longer timeout for race with benchmarks
379381
"-run=^$", // nothing. only benchmarks.
@@ -1069,7 +1071,7 @@ func (t *tester) runHostTest(dir, pkg string) error {
10691071
if err := cmd.Run(); err != nil {
10701072
return err
10711073
}
1072-
return t.dirCmd(dir, f.Name(), "-test.short").Run()
1074+
return t.dirCmd(dir, f.Name(), "-test.short="+short()).Run()
10731075
}
10741076

10751077
func (t *tester) cgoTest(dt *distTest) error {
@@ -1570,7 +1572,7 @@ func (t *tester) prebuiltGoPackageTestBinary() string {
15701572
func (t *tester) runPrecompiledStdTest(timeout time.Duration) error {
15711573
bin := t.prebuiltGoPackageTestBinary()
15721574
fmt.Fprintf(os.Stderr, "# %s: using pre-built %s...\n", stdMatches[0], bin)
1573-
cmd := exec.Command(bin, "-test.short", "-test.timeout="+timeout.String())
1575+
cmd := exec.Command(bin, "-test.short="+short(), "-test.timeout="+timeout.String())
15741576
cmd.Dir = filepath.Dir(bin)
15751577
cmd.Stdout = os.Stdout
15761578
cmd.Stderr = os.Stderr

0 commit comments

Comments
 (0)