Skip to content

Commit

Permalink
cmd/go: cut 'go test -short cmd/go' time by about half
Browse files Browse the repository at this point in the history
Was 50 seconds on unloaded Mac laptop; now 27.
Still longer than I would like, but every little bit helps.

For #26473.

Change-Id: Id4be016ee1555cbc3512eca0ae10236d7f06bd02
Reviewed-on: https://go-review.googlesource.com/c/go/+/177398
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
  • Loading branch information
rsc committed May 16, 2019
1 parent 0c47e24 commit dccd5da
Show file tree
Hide file tree
Showing 54 changed files with 147 additions and 92 deletions.
12 changes: 12 additions & 0 deletions src/cmd/go/go_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1898,6 +1898,7 @@ func TestGoListTest(t *testing.T) {
}

func TestGoListCompiledCgo(t *testing.T) {
tooSlow(t)
tg := testgo(t)
defer tg.cleanup()
tg.parallel()
Expand Down Expand Up @@ -2537,6 +2538,7 @@ func TestCoverageRuns(t *testing.T) {

func TestCoverageDotImport(t *testing.T) {
skipIfGccgo(t, "gccgo has no cover tool")
tooSlow(t)
tg := testgo(t)
defer tg.cleanup()
tg.parallel()
Expand Down Expand Up @@ -2716,6 +2718,7 @@ func TestCoverageFunc(t *testing.T) {
// Issue 24588.
func TestCoverageDashC(t *testing.T) {
skipIfGccgo(t, "gccgo has no cover tool")
tooSlow(t)
tg := testgo(t)
defer tg.cleanup()
tg.parallel()
Expand Down Expand Up @@ -3391,6 +3394,7 @@ func TestVetWithOnlyCgoFiles(t *testing.T) {
if !canCgo {
t.Skip("skipping because cgo not enabled")
}
tooSlow(t)

tg := testgo(t)
defer tg.cleanup()
Expand Down Expand Up @@ -5654,6 +5658,7 @@ func TestTestSkipVetAfterFailedBuild(t *testing.T) {
}

func TestTestVetRebuild(t *testing.T) {
tooSlow(t)
tg := testgo(t)
defer tg.cleanup()
tg.parallel()
Expand Down Expand Up @@ -5933,6 +5938,7 @@ func TestBadCgoDirectives(t *testing.T) {
if !canCgo {
t.Skip("no cgo")
}
tooSlow(t)
tg := testgo(t)
defer tg.cleanup()

Expand Down Expand Up @@ -6047,6 +6053,7 @@ func TestTwoPkgConfigs(t *testing.T) {
if runtime.GOOS == "windows" || runtime.GOOS == "plan9" {
t.Skipf("no shell scripts on %s", runtime.GOOS)
}
tooSlow(t)
tg := testgo(t)
defer tg.cleanup()
tg.parallel()
Expand Down Expand Up @@ -6077,6 +6084,8 @@ func TestCgoCache(t *testing.T) {
if !canCgo {
t.Skip("no cgo")
}
tooSlow(t)

tg := testgo(t)
defer tg.cleanup()
tg.parallel()
Expand Down Expand Up @@ -6127,6 +6136,7 @@ func TestLinkerTmpDirIsDeleted(t *testing.T) {
if !canCgo {
t.Skip("skipping because cgo not enabled")
}
tooSlow(t)

tg := testgo(t)
defer tg.cleanup()
Expand Down Expand Up @@ -6216,6 +6226,7 @@ func TestGoTestWithoutTests(t *testing.T) {

// Issue 25579.
func TestGoBuildDashODevNull(t *testing.T) {
tooSlow(t)
tg := testgo(t)
defer tg.cleanup()
tg.parallel()
Expand All @@ -6228,6 +6239,7 @@ func TestGoBuildDashODevNull(t *testing.T) {
// Issue 25093.
func TestCoverpkgTestOnly(t *testing.T) {
skipIfGccgo(t, "gccgo has no cover tool")
tooSlow(t)
tg := testgo(t)
defer tg.cleanup()
tg.parallel()
Expand Down
1 change: 1 addition & 0 deletions src/cmd/go/testdata/script/build_GOTMPDIR.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
env GO111MODULE=off
[short] skip

# Set GOCACHE to a clean directory to ensure that 'go build' has work to report.
env GOCACHE=$WORK/gocache
Expand Down
1 change: 1 addition & 0 deletions src/cmd/go/testdata/script/build_cache_compile.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
env GO111MODULE=off
[short] skip

# Set up fresh GOCACHE.
env GOCACHE=$WORK/gocache
Expand Down
1 change: 1 addition & 0 deletions src/cmd/go/testdata/script/build_cache_gomips.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
env GO111MODULE=off
[short] skip # rebuilds std for mips

# Set up fresh GOCACHE.
env GOCACHE=$WORK/gocache
Expand Down
1 change: 1 addition & 0 deletions src/cmd/go/testdata/script/build_cache_link.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
env GO111MODULE=off
[short] skip

# Set up fresh GOCACHE.
env GOCACHE=$WORK/gocache
Expand Down
1 change: 1 addition & 0 deletions src/cmd/go/testdata/script/build_cache_output.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
env GO111MODULE=off

[!gc] skip
[short] skip # clears cache, rebuilds too much

# Set up fresh GOCACHE.
env GOCACHE=$WORK/gocache
Expand Down
1 change: 1 addition & 0 deletions src/cmd/go/testdata/script/build_runtime_gcflags.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
env GO111MODULE=off
[short] skip # rebuilds all of std

# Set up fresh GOCACHE.
env GOCACHE=$WORK/gocache
Expand Down
2 changes: 2 additions & 0 deletions src/cmd/go/testdata/script/build_trimpath.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[short] skip

env -r GOROOT_REGEXP=$GOROOT
env -r WORK_REGEXP=$WORK
env GOROOT GOROOT_REGEXP WORK WORK_REGEXP
Expand Down
1 change: 1 addition & 0 deletions src/cmd/go/testdata/script/cgo_syso_issue29253.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
env GO111MODULE=off
[short] skip

# This test tests that we can link in-package syso files that provides symbols
# for cgo. See issue 29253.
Expand Down
1 change: 1 addition & 0 deletions src/cmd/go/testdata/script/clean_testcache.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
env GO111MODULE=off
[short] skip

# go clean -testcache
# should work (see golang.org/issue/29757).
Expand Down
1 change: 1 addition & 0 deletions src/cmd/go/testdata/script/gcflags_patterns.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
env GO111MODULE=off

[!gc] skip 'using -gcflags and -ldflags'
[short] skip

# -gcflags=-e applies to named packages, not dependencies
go build -n -v -gcflags=-e z1 z2
Expand Down
1 change: 1 addition & 0 deletions src/cmd/go/testdata/script/get_dotfiles.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
env GO111MODULE=off
[short] skip

[!exec:git] skip

Expand Down
1 change: 1 addition & 0 deletions src/cmd/go/testdata/script/get_tilde.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
env GO111MODULE=off
[short] skip

# Paths containing windows short names should be rejected before attempting to fetch.
! go get example.com/longna~1.dir/thing
Expand Down
1 change: 1 addition & 0 deletions src/cmd/go/testdata/script/get_unicode.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
env GO111MODULE=off

[!exec:git] skip
[short] skip

# Construct a repository that imports a non-ASCII path.
cd $WORK/_origin/example.com/unicode
Expand Down
1 change: 1 addition & 0 deletions src/cmd/go/testdata/script/install_cleans_build.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
env GO111MODULE=off
[short] skip

# 'go install' with no arguments should clean up after go build
cd mycmd
Expand Down
1 change: 1 addition & 0 deletions src/cmd/go/testdata/script/install_cross_gobin.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
env GO111MODULE=off
[!short] skip # rebuilds std for alternate architecture

cd mycmd
go build mycmd
Expand Down
1 change: 1 addition & 0 deletions src/cmd/go/testdata/script/list_bad_import.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
env GO111MODULE=off
[short] skip

# This test matches mod_list_bad_import, but in GOPATH mode.
# Please keep them in sync.
Expand Down
1 change: 1 addition & 0 deletions src/cmd/go/testdata/script/list_find.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ stdout '^false \[\]'
# should be identical. "go build" derives action IDs (which are used as cache
# keys) from dependencies' action IDs. "go list -find" won't know what the
# dependencies are, so it's can't construct the same action IDs.
[short] skip
go list -find -compiled net
go list -find -compiled -x net
! stderr 'cgo'
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/testdata/script/list_std.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
env GO111MODULE=off

[!gc] skip
[short] skip

# Listing GOROOT should only find standard packages.
cd $GOROOT/src
go list -f '{{if not .Standard}}{{.ImportPath}}{{end}}' ./...
! stdout .
# TODO: ignore _/blah/go/src in output

# Standard packages should include cmd, but not cmd/vendor.
go list ./...
Expand Down
1 change: 1 addition & 0 deletions src/cmd/go/testdata/script/mod_build_versioned.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
env GO111MODULE=on
[short] skip

go get -m rsc.io/fortune/v2

Expand Down
1 change: 1 addition & 0 deletions src/cmd/go/testdata/script/mod_doc.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# go doc should find module documentation

env GO111MODULE=on
[short] skip

go doc y
stdout 'Package y is.*alphabet'
Expand Down
1 change: 1 addition & 0 deletions src/cmd/go/testdata/script/mod_download.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.mod
exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.zip

# download of an invalid path should report the error
[short] skip
! go mod download this.domain.is.invalid/somemodule@v1.0.0
stderr 'this.domain.is.invalid'
! go mod download -json this.domain.is.invalid/somemodule@v1.0.0
Expand Down
2 changes: 2 additions & 0 deletions src/cmd/go/testdata/script/mod_file_proxy.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[short] skip

# Allow (cached) downloads for -mod=readonly.
env GO111MODULE=on
env GOPATH=$WORK/gopath1
Expand Down
6 changes: 4 additions & 2 deletions src/cmd/go/testdata/script/mod_get_commit.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
env GO111MODULE=on
env GOPROXY=$GOPROXY/quiet
[short] skip

# @commit should resolve

# golang.org/x/text/language@commit should not resolve with -m,
# because that's not a module path.
! go get -m golang.org/x/text/language@14c0d48
! go get -d -m golang.org/x/text/language@14c0d48

# ... but it should work without -m.
# because of -d, the compiler should not run
go get -d -x golang.org/x/text/language@14c0d48
! stderr 'compile|cp|gccgo .*language\.a$'

# go get should skip build with no Go files in root
go get golang.org/x/text@14c0d48
go get -d golang.org/x/text@14c0d48

# ... and go get should skip build with -m
go get -m golang.org/x/text@14c0d48

# dropping -d, we should see a build.
[short] skip
go get -x golang.org/x/text/language@14c0d48
stderr 'compile|cp|gccgo .*language\.a$'

Expand Down
1 change: 1 addition & 0 deletions src/cmd/go/testdata/script/mod_get_downgrade.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
env GO111MODULE=on
[short] skip

# downgrade sampler should downgrade quote
go get rsc.io/sampler@v1.0.0
Expand Down
1 change: 1 addition & 0 deletions src/cmd/go/testdata/script/mod_get_indirect.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
env GO111MODULE=on
[short] skip

# get -u should not upgrade anything, since the package
# in the current directory doesn't import anything.
Expand Down
1 change: 1 addition & 0 deletions src/cmd/go/testdata/script/mod_get_local.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Test 'go get' with a local module with a name that is not valid for network lookup.
[short] skip

env GO111MODULE=on
go mod edit -fmt
Expand Down
1 change: 1 addition & 0 deletions src/cmd/go/testdata/script/mod_get_main.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
env GO111MODULE=on
[short] skip

# @patch and @latest within the main module refer to the current version.
# The main module won't be upgraded, but missing dependencies will be added.
Expand Down
1 change: 1 addition & 0 deletions src/cmd/go/testdata/script/mod_get_moved.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
env GO111MODULE=on
env GOPROXY=$GOPROXY/quiet
[short] skip

# A 'go get' that worked at a previous version should continue to work at that version,
# even if the package was subsequently moved into a submodule.
Expand Down
1 change: 1 addition & 0 deletions src/cmd/go/testdata/script/mod_get_patterns.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
env GO111MODULE=on
[short] skip

# If a pattern doesn't match any modules in the build list,
# and -m is used, an error should be reported.
Expand Down
12 changes: 6 additions & 6 deletions src/cmd/go/testdata/script/mod_get_upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@ stdout 'rsc.io/quote v1.5.1'
grep 'rsc.io/quote v1.5.1$' go.mod

# get -m -u should update all dependencies
go get -m -u
go get -d -m -u
grep 'rsc.io/quote v1.5.2$' go.mod
grep 'golang.org/x/text [v0-9a-f\.-]+ // indirect' go.mod

# get -u rsc.io/sampler should update only sampler's dependencies
cp go.mod-v1.5.1 go.mod
go get -u rsc.io/sampler
go get -d -u rsc.io/sampler
grep 'rsc.io/quote v1.5.1$' go.mod
grep 'golang.org/x/text [v0-9a-f\.-]+ // indirect' go.mod

# move to a pseudo-version after any tags
go get -m rsc.io/quote@dd9747d
go get -d -m rsc.io/quote@dd9747d
grep 'rsc.io/quote v0.0.0-20180628003336-dd9747d19b04' go.mod

# get -u should not jump off newer pseudo-version to earlier tag
go get -m -u
go get -d -m -u
grep 'rsc.io/quote v0.0.0-20180628003336-dd9747d19b04' go.mod

# move to earlier pseudo-version
go get -m rsc.io/quote@e7a685a342
go get -d -m rsc.io/quote@e7a685a342
grep 'rsc.io/quote v0.0.0-20180214005133-e7a685a342c0' go.mod

# get -u should jump off earlier pseudo-version to newer tag
go get -m -u
go get -d -m -u
grep 'rsc.io/quote v1.5.2' go.mod

-- go.mod --
Expand Down
2 changes: 2 additions & 0 deletions src/cmd/go/testdata/script/mod_gobuild_import.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[short] skip

# go/build's Import should find modules by invoking the go command

go build -o $WORK/testimport.exe ./testimport
Expand Down
1 change: 1 addition & 0 deletions src/cmd/go/testdata/script/mod_internal.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
env GO111MODULE=on
[short] skip

# golang.org/x/internal should be importable from other golang.org/x modules.
rm go.mod
Expand Down
1 change: 1 addition & 0 deletions src/cmd/go/testdata/script/mod_list.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
env GO111MODULE=on
[short] skip

# list {{.Dir}} shows main module and go.mod but not not-yet-downloaded dependency dir.
go list -m -f '{{.Path}} {{.Main}} {{.GoMod}} {{.Dir}}' all
Expand Down
2 changes: 2 additions & 0 deletions src/cmd/go/testdata/script/mod_list_dir.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[short] skip

# go list with path to directory should work

env GO111MODULE=off
Expand Down
1 change: 1 addition & 0 deletions src/cmd/go/testdata/script/mod_list_std.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ env GO111MODULE=on
env GOPROXY=off

[!gc] skip
[short] skip

# Outside of GOROOT, our vendored packages should be reported as part of the standard library.
go list -f '{{if .Standard}}{{.ImportPath}}{{end}}' std cmd
Expand Down
1 change: 1 addition & 0 deletions src/cmd/go/testdata/script/mod_outside.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
env GO111MODULE=on
[short] skip

# This script tests commands in module mode outside of any module.
#
Expand Down
Loading

0 comments on commit dccd5da

Please sign in to comment.