]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: use build cache for tests when GOCACHE is unset
authorRuss Cox <rsc@golang.org>
Tue, 12 Jun 2018 20:05:29 +0000 (16:05 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 12 Jun 2018 20:31:40 +0000 (20:31 +0000)
Before this CL, if you had GOCACHE=/some/dir, then the cmd/go tests used it.
But if you were relying on the implicit behavior that GOCACHE being empty
meant an appropriate system-specific cache directory, then the cmd/go tests
ran with no cache at all, which makes them about 4X slower.

During all.bash GOCACHE is set to a fresh temporary directory and is therefore
already getting proper caching; this CL mainly helps people running 'go test cmd/go'
by hand.

Change-Id: I7c322ca79b877c1d0a3b448b95d5354fbfcba7f8
Reviewed-on: https://go-review.googlesource.com/118320
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/go/go_test.go

index abe23ff52dd5d9b764c527eb3029af44e71c6d27..21dc9607d55d6b4ab3c37d3fb27c5aae4693f593 100644 (file)
@@ -99,6 +99,7 @@ func init() {
 var testGOROOT string
 
 var testCC string
+var testGOCACHE string
 
 // The TestMain function creates a go command for testing purposes and
 // deletes it after the tests have been run.
@@ -175,6 +176,13 @@ func TestMain(m *testing.M) {
                        }
                }
 
+               out, err = exec.Command(gotool, "env", "GOCACHE").CombinedOutput()
+               if err != nil {
+                       fmt.Fprintf(os.Stderr, "could not find testing GOCACHE: %v\n%s", err, out)
+                       os.Exit(2)
+               }
+               testGOCACHE = strings.TrimSpace(string(out))
+
                // As of Sept 2017, MSan is only supported on linux/amd64.
                // https://github.com/google/sanitizers/wiki/MemorySanitizer#getting-memorysanitizer
                canMSan = canCgo && runtime.GOOS == "linux" && runtime.GOARCH == "amd64"
@@ -198,7 +206,7 @@ func TestMain(m *testing.M) {
        }
        os.Setenv("HOME", "/test-go-home-does-not-exist")
        if os.Getenv("GOCACHE") == "" {
-               os.Setenv("GOCACHE", "off") // because $HOME is gone
+               os.Setenv("GOCACHE", testGOCACHE) // because $HOME is gone
        }
 
        r := m.Run()
@@ -3261,9 +3269,9 @@ func TestGoTestCoverMultiPackage(t *testing.T) {
        tg := testgo(t)
        defer tg.cleanup()
        tg.run("test", "-cover", "./testdata/testcover/...")
-       tg.grepStdout(`\?.*testdata/testcover/pkg1.*\d\.\d\d\ds.*coverage:.*0\.0% of statements \[no test files\]`, "expected [no test files] for pkg1")
-       tg.grepStdout(`ok.*testdata/testcover/pkg2.*\d\.\d\d\ds.*coverage:.*0\.0% of statements \[no tests to run\]`, "expected [no tests to run] for pkg2")
-       tg.grepStdout(`ok.*testdata/testcover/pkg3.*\d\.\d\d\ds.*coverage:.*100\.0% of statements`, "expected 100% coverage for pkg3")
+       tg.grepStdout(`\?.*testdata/testcover/pkg1.*(\d\.\d\d\ds|cached).*coverage:.*0\.0% of statements \[no test files\]`, "expected [no test files] for pkg1")
+       tg.grepStdout(`ok.*testdata/testcover/pkg2.*(\d\.\d\d\ds|cached).*coverage:.*0\.0% of statements \[no tests to run\]`, "expected [no tests to run] for pkg2")
+       tg.grepStdout(`ok.*testdata/testcover/pkg3.*(\d\.\d\d\ds|cached).*coverage:.*100\.0% of statements`, "expected 100% coverage for pkg3")
 }
 
 // issue 24570
@@ -3272,9 +3280,9 @@ func TestGoTestCoverprofileMultiPackage(t *testing.T) {
        defer tg.cleanup()
        tg.creatingTemp("testdata/cover.out")
        tg.run("test", "-coverprofile=testdata/cover.out", "./testdata/testcover/...")
-       tg.grepStdout(`\?.*testdata/testcover/pkg1.*\d\.\d\d\ds.*coverage:.*0\.0% of statements \[no test files\]`, "expected [no test files] for pkg1")
-       tg.grepStdout(`ok.*testdata/testcover/pkg2.*\d\.\d\d\ds.*coverage:.*0\.0% of statements \[no tests to run\]`, "expected [no tests to run] for pkg2")
-       tg.grepStdout(`ok.*testdata/testcover/pkg3.*\d\.\d\d\ds.*coverage:.*100\.0% of statements`, "expected 100% coverage for pkg3")
+       tg.grepStdout(`\?.*testdata/testcover/pkg1.*(\d\.\d\d\ds|cached).*coverage:.*0\.0% of statements \[no test files\]`, "expected [no test files] for pkg1")
+       tg.grepStdout(`ok.*testdata/testcover/pkg2.*(\d\.\d\d\ds|cached).*coverage:.*0\.0% of statements \[no tests to run\]`, "expected [no tests to run] for pkg2")
+       tg.grepStdout(`ok.*testdata/testcover/pkg3.*(\d\.\d\d\ds|cached).*coverage:.*100\.0% of statements`, "expected 100% coverage for pkg3")
        if out, err := ioutil.ReadFile("testdata/cover.out"); err != nil {
                t.Error(err)
        } else {