You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
dontcover represents things like protobufs or other generated code that I don't want to include in the coverage report.
I want to run my tests for the package and all other subpackages and get a coverage report excluding packages containing the generated code.
What did you expect to see?
This runs all tests in all packages (expected).
$ go test -coverpkg=./... -coverprofile=cover.out -v ./...
=== RUN TestSomething
--- PASS: TestSomething (0.00s)
PASS
coverage: 0.0% of statements in ./...
ok github.com/F21/coverpkgtest 1.157s coverage: 0.0% of statements in ./...
=== RUN TestSomePkg
--- PASS: TestSomePkg (0.00s)
PASS
coverage: 0.0% of statements in ./...
ok github.com/F21/coverpkgtest/somepkg 2.896s coverage: 0.0% of statements in ./...
? github.com/F21/coverpkgtest/somepkg/dontcover [no test files]
This only runs tests in somepkg. The ./... at the end of the go test command being ignored is also surprising. In addition, go list lists all packages, so it was also surprising that tests in the root package was skipped
$ go test -coverpkg=$(go list ./...) -coverprofile=cover.out -v ./...
=== RUN TestSomePkg
--- PASS: TestSomePkg (0.00s)
PASS
coverage: 0.0% of statements in github.com/F21/coverpkgtest
ok github.com/F21/coverpkgtest/somepkg 1.581s coverage: 0.0% of statements in github.com/F21/coverpkgtest
? github.com/F21/coverpkgtest/somepkg/dontcover [no test files]
This runs all tests. Adding a space between the equals and the packages to test runs all tests. I am not sure why the space makes a difference
$ go test -coverpkg= $(go list ./...) -coverprofile=cover.out -v ./...
=== RUN TestSomething
--- PASS: TestSomething (0.00s)
PASS
coverage: 0.0% of statements
ok github.com/F21/coverpkgtest 1.370s coverage: 0.0% of statements
=== RUN TestSomePkg
--- PASS: TestSomePkg (0.00s)
PASS
coverage: 0.0% of statements
ok github.com/F21/coverpkgtest/somepkg 2.652s coverage: 0.0% of statements
? github.com/F21/coverpkgtest/somepkg/dontcover [no test files]
This does what I need, by add a space between the equals and the packages to test:
$ go test -coverpkg= $(go list ./... | grep -v dontcover) -coverprofile=cover.out -v ./...
=== RUN TestSomething
--- PASS: TestSomething (0.00s)
PASS
coverage: 0.0% of statements
ok github.com/F21/coverpkgtest 0.156s coverage: 0.0% of statements
=== RUN TestSomePkg
--- PASS: TestSomePkg (0.00s)
PASS
coverage: 0.0% of statements
ok github.com/F21/coverpkgtest/somepkg 0.255s coverage: 0.0% of statements
This works as expected:
$ go test -coverpkg=github.com/F21/coverpkgtest,github.com/F21/coverpkgtest/somepkg -v ./...
=== RUN TestSomething
--- PASS: TestSomething (0.00s)
PASS
coverage: 0.0% of statements in github.com/F21/coverpkgtest, github.com/F21/coverpkgtest/somepkg
ok github.com/F21/coverpkgtest 2.923s coverage: 0.0% of statements in github.com/F21/coverpkgtest, github.com/F21/coverpkgtest/somepkg
=== RUN TestSomePkg
--- PASS: TestSomePkg (0.00s)
PASS
coverage: 0.0% of statements in github.com/F21/coverpkgtest, github.com/F21/coverpkgtest/somepkg
ok github.com/F21/coverpkgtest/somepkg 1.545s coverage: 0.0% of statements in github.com/F21/coverpkgtest, github.com/F21/coverpkgtest/somepkg
? github.com/F21/coverpkgtest/somepkg/dontcover [no test files]
What did you see instead?
See above
The text was updated successfully, but these errors were encountered:
This has nothing to do with Go. It's all just because of how the shell behaves. When you write
go test -coverpkg=$(go list ./...)
you didn't quote the $(), so it generates multiple arguments. In effect you are passing one package to -coverpkg, and the remaining output from go list becomes arguments to go test.
Uh oh!
There was an error while loading. Please reload this page.
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?1.10 RC2
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?Windows 10 64-bit (latest release + updates)
What did you do?
Code is available here: https://github.com/F21/coverpkgtest.git
I have a project arranged like so:
This uses Ben Johnson's standard layout where the domain model is in the package root.
dontcover
represents things like protobufs or other generated code that I don't want to include in the coverage report.I want to run my tests for the package and all other subpackages and get a coverage report excluding packages containing the generated code.
What did you expect to see?
This runs all tests in all packages (expected).
This only runs tests in
somepkg
. The./...
at the end of thego test
command being ignored is also surprising. In addition,go list
lists all packages, so it was also surprising that tests in the root package was skippedThis runs all tests. Adding a space between the equals and the packages to test runs all tests. I am not sure why the space makes a difference
This does what I need, by add a space between the equals and the packages to test:
This works as expected:
What did you see instead?
See above
The text was updated successfully, but these errors were encountered: