tg.run("test", "-short", "-cover", "-covermode=atomic", "-coverpkg=coverdep/p1", "coverdep")
}
+func TestCoverageDepLoop(t *testing.T) {
+ tg := testgo(t)
+ defer tg.cleanup()
+ tg.parallel()
+ tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
+ // coverdep2/p1's xtest imports coverdep2/p2 which imports coverdep2/p1.
+ // Make sure that coverage on coverdep2/p2 recompiles coverdep2/p2.
+ tg.run("test", "-short", "-cover", "coverdep2/p1")
+ tg.grepStdout("coverage: 100.0% of statements", "expected 100.0% coverage")
+}
+
func TestCoverageImportMainLoop(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
// This will cause extra compilation, so for now we only do it
// when testCover is set. The conditions are more general, though,
// and we may find that we need to do it always in the future.
- recompileForTest(pmain, p, ptest)
+ recompileForTest(pmain, p, ptest, pxtest)
}
for _, cp := range pmain.Internal.Imports {
return stk
}
-func recompileForTest(pmain, preal, ptest *load.Package) {
+func recompileForTest(pmain, preal, ptest, pxtest *load.Package) {
// The "test copy" of preal is ptest.
// For each package that depends on preal, make a "test copy"
// that depends on ptest. And so on, up the dependency tree.
testCopy := map[*load.Package]*load.Package{preal: ptest}
for _, p := range load.PackageList([]*load.Package{pmain}) {
+ if p == preal {
+ continue
+ }
// Copy on write.
- didSplit := false
+ didSplit := p == pmain || p == pxtest
split := func() {
if didSplit {
return