-
Notifications
You must be signed in to change notification settings - Fork 17.4k
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
cmd/go: test coverpkg=all ./... with test only packages will fail to build #27333
Comments
I met this issue in real world. https://github.com/mercari/datastore/tree/v1.4.0/testbed
|
Change https://golang.org/cl/164198 mentions this issue: |
This is something that has just bit me as well. Anyways if anyone is stuck because of this like me, here is tiny workaround:
The above workaround only works when your directory structure is as follows:
That is your test only package are always inside a directory named |
I found a tool called go-acc that solved this problem for me. 🎉 # Download and install go-acc
$ go get -u github.com/ory/go-acc
# Run it against some package(s)
$ go-acc github.com/some/package
$ go-acc .
$ go-acc ./...
$ go-acc $(glide novendor) Here's the blogpost I found this tool on: https://www.ory.sh/golang-go-code-coverage-accurate Thanks ory; if you see this, you saved me hours of pain. |
Add a stub file for golang/go#27333
when i use go1.14, it appears too.. What version of Go are you using (
|
I just come across this problem as well. I tested with
I think the In _testmain.go, there's some function calls like Apparently, it registers some duplicate go files that doesn't import in current package 'hello'. If Maybe the flags passed to I use this |
The coverpkg expects comma seperated package names, so the workaround that worked for me |
Hello, any chance that this will be fixed anytime soon? This issue if very painful for us |
Any updates here? I'm also getting different results when using @itsmeadi suggestion |
We can reproduce it with the following setup and the workaround we use is written below. It might help @elichai and others. Reproduction
So we have a tree:
The coverage test fails with the following message:
This message above suggests that the error is caused by sub package WorkaroundThe workaround for the example above is to create an empty package for
This worked, as every package has at least one non-test file:
|
Change https://golang.org/cl/288292 mentions this issue: |
I've sent a fix above, which will presumably make it into Go 1.17. Until then, I agree with previous posters that the easiest workaround is to avoid test-only packages by dropping a no-op non-test file in those packages. For example: |
@mvdan what's the best way to check if it solves the problems? (I know how to install tip but not how to install a compiler from an open PR ) |
@elichai |
Adds a workaround for golang/go#27333 to make `make coverage` work.
@seankhliao it Works! |
…#1480) * Add dummy go files for test only package, to mitigate golang/go#27333 * Stop ignoring errors when producing the coverage * Add comments explaining the dummy go files * Make the coverage output non-json
Add a dummy file so that we can measure coverage for the whole project Check golang/go#27333.
Separate the loading of repo definitions from JSON file from `LoadRepositories()` to a standalone function `loadRepositoriesFromFile()`, to make it easy to reuse it in the future. Add unit tests for `LoadRepositories()` function. Exclude github.com/osbuild/osbuild-composer/internal/rpmmd/test package from test coverage. Package with just tests and no other code makes `go test` to fail. This should be fixed in go 1.17. See golang/go#27333 Signed-off-by: Tomas Hozza <thozza@redhat.com>
Separate the loading of repo definitions from JSON file from `LoadRepositories()` to a standalone function `loadRepositoriesFromFile()`, to make it easy to reuse it in the future. Add unit tests for `LoadRepositories()` function. Exclude github.com/osbuild/osbuild-composer/internal/rpmmd/test package from test coverage. Package with just tests and no other code makes `go test` to fail. This should be fixed in go 1.17. See golang/go#27333 Signed-off-by: Tomas Hozza <thozza@redhat.com>
Separate the loading of repo definitions from JSON file from `LoadRepositories()` to a standalone function `loadRepositoriesFromFile()`, to make it easy to reuse it in the future. Add unit tests for `LoadRepositories()` function. Exclude github.com/osbuild/osbuild-composer/internal/rpmmd/test package from test coverage. Package with just tests and no other code makes `go test` to fail. This should be fixed in go 1.17. See golang/go#27333 Signed-off-by: Tomas Hozza <thozza@redhat.com>
Separate the loading of repo definitions from JSON file from `LoadRepositories()` to a standalone function `loadRepositoriesFromFile()`, to make it easy to reuse it in the future. Add unit tests for `LoadRepositories()` function. Exclude github.com/osbuild/osbuild-composer/internal/rpmmd/test package from test coverage. Package with just tests and no other code makes `go test` to fail. This should be fixed in go 1.17. See golang/go#27333 Signed-off-by: Tomas Hozza <thozza@redhat.com>
Separate the loading of repo definitions from JSON file from `LoadRepositories()` to a standalone function `loadRepositoriesFromFile()`, to make it easy to reuse it in the future. Add unit tests for `LoadRepositories()` function. Exclude github.com/osbuild/osbuild-composer/internal/rpmmd/test package from test coverage. Package with just tests and no other code makes `go test` to fail. This should be fixed in go 1.17. See golang/go#27333 Signed-off-by: Tomas Hozza <thozza@redhat.com>
Separate the loading of repo definitions from JSON file from `LoadRepositories()` to a standalone function `loadRepositoriesFromFile()`, to make it easy to reuse it in the future. Add unit tests for `LoadRepositories()` function. Exclude github.com/osbuild/osbuild-composer/internal/rpmmd/test package from test coverage. Package with just tests and no other code makes `go test` to fail. This should be fixed in go 1.17. See golang/go#27333 Signed-off-by: Tomas Hozza <thozza@redhat.com>
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?1.11
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?linux amd64
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.
Ran
go test -coverpkg=all ./...
with the following folder structure:Content of files is irrelevant.
Apparently
go test -cover ./...
works, so it's specific to-coverpkg
Also deleting
foo_test.go
worksWhat did you expect to see?
What did you see instead?
The text was updated successfully, but these errors were encountered: