ptest.Internal.Imports = append(imports, p.Internal.Imports...)
ptest.Internal.RawImports = str.StringList(rawTestImports, p.Internal.RawImports)
ptest.Internal.ForceLibrary = true
+ ptest.Internal.BuildInfo = ""
ptest.Internal.Build = new(build.Package)
*ptest.Internal.Build = *p.Internal.Build
m := map[string][]token.Position{}
},
Internal: PackageInternal{
Build: &build.Package{Name: "main"},
+ BuildInfo: p.Internal.BuildInfo,
Asmflags: p.Internal.Asmflags,
Gcflags: p.Internal.Gcflags,
Ldflags: p.Internal.Ldflags,
copy(p1.Imports, p.Imports)
p = p1
p.Target = ""
+ p.Internal.BuildInfo = ""
}
// Update p.Internal.Imports to use test copies.
p.Internal.Imports[i] = p1
}
}
+
+ // Don't compile build info from a main package. This can happen
+ // if -coverpkg patterns include main packages, since those packages
+ // are imported by pmain.
+ if p.Internal.BuildInfo != "" && p != pmain {
+ split()
+ }
}
}
--- /dev/null
+# This test checks that multiple main packages can be tested
+# with -coverpkg=all without duplicate symbol errors.
+# Verifies golang.org/issue/30374.
+
+env GO111MODULE=on
+
+[short] skip
+
+go test -coverpkg=all ./main1 ./main2
+
+-- go.mod --
+module example.com/cov
+
+-- main1/main1.go --
+package main
+
+func main() {}
+
+-- main1/main1_test.go --
+package main
+
+import "testing"
+
+func TestMain1(t *testing.T) {}
+
+-- main2/main2.go --
+package main
+
+func main() {}
+
+-- main2/main2_test.go --
+package main
+
+import "testing"
+
+func TestMain2(t *testing.T) {}
+