}
}
- // 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. See golang.org/issue/30907.
- if p.Internal.BuildInfo != "" && p != pmain {
+ // Force main packages the test imports to be built as libraries.
+ // Normal imports of main packages are forbidden by the package loader,
+ // but this can still happen if -coverpkg patterns include main packages:
+ // covered packages are imported by pmain. Linking multiple packages
+ // compiled with '-p main' causes duplicate symbol errors.
+ // See golang.org/issue/30907, golang.org/issue/34114.
+ if p.Name == "main" && p != pmain {
split()
}
}
# 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
+# Verifies golang.org/issue/30374, golang.org/issue/34114.
[short] skip
+cd $GOPATH/src/example.com/cov
+
+env GO111MODULE=on
+go test -coverpkg=all ./...
+env GO111MODULE=off
go test -coverpkg=all ./...
--- go.mod --
+-- $GOPATH/src/example.com/cov/go.mod --
module example.com/cov
--- mainonly/mainonly.go --
+-- $GOPATH/src/example.com/cov/mainonly/mainonly.go --
package main
func main() {}
--- mainwithtest/mainwithtest.go --
+-- $GOPATH/src/example.com/cov/mainwithtest/mainwithtest.go --
package main
func main() {}
func Foo() {}
--- mainwithtest/mainwithtest_test.go --
+-- $GOPATH/src/example.com/cov/mainwithtest/mainwithtest_test.go --
package main
import "testing"
Foo()
}
--- xtest/x.go --
+-- $GOPATH/src/example.com/cov/xtest/x.go --
package x
--- xtest/x_test.go --
+-- $GOPATH/src/example.com/cov/xtest/x_test.go --
package x_test
import "testing"