diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go index ac47adb8e7d..9009ec92e13 100644 --- a/src/cmd/go/go_test.go +++ b/src/cmd/go/go_test.go @@ -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") +} diff --git a/src/cmd/go/internal/test/test.go b/src/cmd/go/internal/test/test.go index 7f7ce63eda8..bf684809e3a 100644 --- a/src/cmd/go/internal/test/test.go +++ b/src/cmd/go/internal/test/test.go @@ -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) }