]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: ignore coverpkg match on sync/atomic in atomic coverage mode
authorIan Lance Taylor <iant@golang.org>
Mon, 5 Feb 2018 02:45:39 +0000 (18:45 -0800)
committerIan Lance Taylor <iant@golang.org>
Mon, 5 Feb 2018 15:32:06 +0000 (15:32 +0000)
Otherwise we get into a dependency loop as we try to apply coverage
analysis to sync/atomic when the coverage analysis itself requires
sync/atomic.

Fixes #23694

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

index ac47adb8e7dcf5ca423962e7cd52ce4bd132052a..9009ec92e13ca14e3ef44900aea1e688b5500926 100644 (file)
@@ -5686,3 +5686,16 @@ func TestCpuprofileTwice(t *testing.T) {
        tg.run("test", "-o="+bin, "-cpuprofile="+out, "x")
        tg.mustExist(out)
 }
+
+// Issue 23694.
+func TestAtomicCoverpkgAll(t *testing.T) {
+       tg := testgo(t)
+       defer tg.cleanup()
+       tg.parallel()
+
+       tg.tempFile("src/x/x.go", `package x; import _ "sync/atomic"; func F() {}`)
+       tg.tempFile("src/x/x_test.go", `package x; import "testing"; func TestF(t *testing.T) { F() }`)
+       tg.setenv("GOPATH", tg.path("."))
+       tg.run("test", "-coverpkg=all", "-race", "x")
+       tg.run("test", "-coverpkg=all", "-covermode=atomic", "x")
+}
index 7f7ce63eda8cc4abf714015df1fe8e21431a280b..bf684809e3a0c82e303c83f6ae2b966627cb8a3f 100644 (file)
@@ -659,6 +659,15 @@ func runTest(cmd *base.Command, args []string) {
                                        haveMatch = true
                                }
                        }
+
+                       // Silently ignore attempts to run coverage on
+                       // sync/atomic when using atomic coverage mode.
+                       // Atomic coverage mode uses sync/atomic, so
+                       // we can't also do coverage on it.
+                       if testCoverMode == "atomic" && p.Standard && p.ImportPath == "sync/atomic" {
+                               continue
+                       }
+
                        if haveMatch {
                                testCoverPkgs = append(testCoverPkgs, p)
                        }