-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/go: -coverpkg=all gives different coverage value when run on a package list vs ./... #23883
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It's not clear to me that it has anything to do with whether you specify One issue is that |
I'm marking this for 1.11 since as far as I can tell |
@ianlancetaylor To make this easier to explain, I have a test only package containing some non test files to run cgo functions. When running test without ./... -coverpkg only matches my test package for some reason, which is why it gave 94.4%. However running with ./... includes my other packages that I'm actually interested in, which then gave a lower value of 47.3%. Modifiying the test case such that func Foo is in a separate folder than the test function should show 0% coverage vs 100% coverage with running test -coverpkg=foopackage/... with ./... and without. |
I'm having a related problem where I'm using
|
@jdef Try running |
data point: I created a coverage_imports.go file in my project's e2e/ (test-only) package. it anonymously imports every other package in the project, besides itself. when I pre-compile the e2e/ test binary (via |
/cc @bcmills |
Description of my experiences, which led me here: https://groups.google.com/forum/#!topic/golang-nuts/63zlrBhnNw8 My use case: One package with tests I want to run isolated from the other tests but report coverage on all dependent sibling packages. |
I have a similar use case. I have it working under windows with:
even though it throws the "no packages being tested depend on match for pattern" warning. I absolutely cannot make it work under Ubuntu 18.04. |
Likely the same underlying cause as #23910. |
Not completely clear I understand all aspects of this bug, but I agree with @bcmills that this is most likely the same bug as #23910. FWIW we've moved away from the model in which all -coverpkg packages are force-imported into every test, this was done as part of the coverage redesign in Go 1.20. Closing this bug out, please reopen if needed. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?1.10
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOBIN=""
GOCACHE="/home/chotepud/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="
/go"/.local/go"GORACE=""
GOROOT="
GOTMPDIR=""
GOTOOLDIR="~/.local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build941063065=/tmp/go-build -gno-record-gcc-switches"
What did you do?
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
Run both
go test -coverpkg=all
andgo test -coverpkg=all ./...
What did you expect to see?
Same coverage value for
go test -coverpkg=all
vsgo test -coverpkg=all ./...
What did you see instead?
go test -coverpkg=all ./...
go test -coverpkg=all
In actual packages the difference could be as big as
go test -coverpkg=all ./...
47.3% vsgo test -coverpkg=all
94.4% when comparing the same package.The text was updated successfully, but these errors were encountered: