go: cmd/go: test coverpkg=all ./... with test only packages will fail to build
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:
├── foo.go
├── foo_test.go
└── tests
└── tests_test.go
Content of files is irrelevant.
Apparently go test -cover ./...
works, so it’s specific to -coverpkg
Also deleting foo_test.go
works
What did you expect to see?
ok _/<HOME>/go/src/foo 0.001s coverage: 0.0% of statements [no tests to run]
ok _/<HOME>/go/src/foo/tests 0.004s coverage: 0.0% of statements [no tests to run]
What did you see instead?
go build _/<HOME>/go/src/foo/tests: no non-test Go files in go/src/foo/tests
FAIL _/<HOME>/go/src/foo [build failed]
ok _/<HOME>/go/src/foo/tests 0.001s coverage: 0.0% of statements in all [no tests to run]
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 3
- Comments: 16 (4 by maintainers)
Commits related to this issue
- Make workaround for go coverpkg bug (#19) Add a stub file for golang/go#27333 — committed to GetStream/machinery by ferhatelmas 4 years ago
- Fix `make coverage` Adds a workaround for https://github.com/golang/go/issues/27333 to make `make coverage` work. — committed to 2uasimojo/aws-account-operator by 2uasimojo 3 years ago
- Add dummy go files for test only package, to mitigate golang/go#27333 — committed to kaspanet/kaspad by elichai 3 years ago
- Add dummy go files for test only package, to mitigate golang/go#27333 (#1480) * Add dummy go files for test only package, to mitigate golang/go#27333 * Stop ignoring errors when producing the cove... — committed to kaspanet/kaspad by elichai 3 years ago
- Workaround a coverage go bug for test only package Add a dummy file so that we can measure coverage for the whole project Check https://github.com/golang/go/issues/27333. — committed to ubuntu/adsys by didrocks 3 years ago
- rpmmd: separate loading of repo definitions from file and add tests Separate the loading of repo definitions from JSON file from `LoadRepositories()` to a standalone function `loadRepositoriesFromFil... — committed to thozza/osbuild-composer by thozza 3 years ago
- rpmmd: separate loading of repo definitions from file and add tests Separate the loading of repo definitions from JSON file from `LoadRepositories()` to a standalone function `loadRepositoriesFromFil... — committed to thozza/osbuild-composer by thozza 3 years ago
- rpmmd: separate loading of repo definitions from file and add tests Separate the loading of repo definitions from JSON file from `LoadRepositories()` to a standalone function `loadRepositoriesFromFil... — committed to thozza/osbuild-composer by thozza 3 years ago
- rpmmd: separate loading of repo definitions from file and add tests Separate the loading of repo definitions from JSON file from `LoadRepositories()` to a standalone function `loadRepositoriesFromFil... — committed to thozza/osbuild-composer by thozza 3 years ago
- rpmmd: separate loading of repo definitions from file and add tests Separate the loading of repo definitions from JSON file from `LoadRepositories()` to a standalone function `loadRepositoriesFromFil... — committed to osbuild/osbuild-composer by thozza 3 years ago
- rpmmd: separate loading of repo definitions from file and add tests Separate the loading of repo definitions from JSON file from `LoadRepositories()` to a standalone function `loadRepositoriesFromFil... — committed to achilleas-k/osbuild-composer by thozza 3 years ago
The coverpkg expects comma seperated package names, so the workaround that worked for me
go test ./... -coverpkg=$(go list ./... | grep -v test | tr "\n" ",") -coverprofile=coverage.out
assuming your test package name containstest
as a substringI met this issue in real world. This issue is very painful… because, unrelated packages will be
build failed
without an error message… I foundgo build go.mercari.io/datastore/testbed: no non-test Go files in /go/src/go.mercari.io/datastore/testbed
message, but I can’t found relation between this message tobuild faled
. and I see it occasionally, but I never had a problem until now.https://github.com/mercari/datastore/tree/v1.4.0/testbed https://circleci.com/gh/mercari/datastore/219
I found a tool called go-acc that solved this problem for me. 🎉
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.
@elichai
gotip download <CL number>
eg:gotip download 288292