Commit f047422a authored by Russ Cox's avatar Russ Cox Committed by Brad Fitzpatrick

cmd/go: fix -covermode=atomic use of sync/atomic in -coverpkg matches

If we're using -covermode=atomic with -coverpkg, to add coverage
to more than just the package being tested, then we need to make sure
to make sync/atomic available to the compiler for every package
being recompiled for coverage.

Fixes #22728.

Change-Id: I27f88f6a62e37d4a7455554cd03c8ca2b21f81a4
Reviewed-on: https://go-review.googlesource.com/81497
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 66fcf454
......@@ -2416,6 +2416,14 @@ func TestCoverageUsesAtomicModeForRace(t *testing.T) {
checkCoverage(tg, data)
}
func TestCoverageSyncAtomicImport(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.parallel()
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
tg.run("test", "-short", "-cover", "-covermode=atomic", "-coverpkg=coverdep/p1", "coverdep")
}
func TestCoverageImportMainLoop(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
......
......@@ -670,6 +670,9 @@ func runTest(cmd *base.Command, args []string) {
coverFiles = append(coverFiles, p.CgoFiles...)
coverFiles = append(coverFiles, p.TestGoFiles...)
p.Internal.CoverVars = declareCoverVars(p.ImportPath, coverFiles...)
if testCover && testCoverMode == "atomic" {
ensureImport(p, "sync/atomic")
}
}
}
......
package p
import _ "coverdep/p1"
func F() {
}
package p
import "testing"
func Test(t *testing.T) {
F()
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment