Skip to content

test coverage: subprocess coverage of binaries built with -cover not included with default coverage. #63660

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

Closed
davidmdm opened this issue Oct 22, 2023 · 1 comment

Comments

@davidmdm
Copy link

davidmdm commented Oct 22, 2023

What version of Go are you using (go version)?

$ go version
go version go1.21.3 darwin/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH='amd64'
GOOS='darwin'

What did you do?

I am running tests that run coverage binaries that write to their covdata to the -test.gocoverdir however the reported coverage is wrong. The reported coverage only takes into account the covdata generated by the go test process and not also the coverage generated by the subprocesses that also generate coverage to the same gocoverdir.

To demonstrate this I have a newly created package that deals with signals. In order to test this package I had to create an "acceptance binary" (a binary created with go build -cover) and use it as part of my regular tests so that I can send signals and test the functionality of my library.

However when I run go test -cover although the unit test coverage and the acceptance-binary coverage are being written to the same gocoverdir the go test command only shows the coverage of the unit tests and so does the cover profile.

However if you set the gocoverdir manually and build the percentage and textfmt cover profile manually you get complete coverage. This should be the default of the go test command. To run and build its coverage from all generated coverage.

Follow these steps to reproduce:

git clone [email protected]:davidmdm/xcontext.git
cd xcontext
git checkout gocoverdir

# This simply runs a normal coverage and you will see only 20% coverage reported
./coverage-regular.sh

# This sets a gocoverdir to a local folder and builds the percentage from it. You will notice the go test
# command still reports 20% coverage, but the covdata percent command reports 100% coverage.
./coverage-gocoverdir.sh

What did you expect to see?

I expected the go test to use all the covdata generated and present correct coverage.

Note the difference between a normal run and one where covdata is manually collected and proccessed:

Go test output:

mode: set
github.com/davidmdm/xcontext/signal.go:12.123,23.12 4 0
github.com/davidmdm/xcontext/signal.go:23.12,27.10 3 0
github.com/davidmdm/xcontext/signal.go:28.26,30.10 2 0
github.com/davidmdm/xcontext/signal.go:31.24,31.24 0 0
github.com/davidmdm/xcontext/signal.go:32.15,32.15 0 0
github.com/davidmdm/xcontext/signal.go:35.3,35.19 1 0
github.com/davidmdm/xcontext/signal.go:38.2,40.18 2 0
github.com/davidmdm/xcontext/signal.go:40.18,41.18 1 0
github.com/davidmdm/xcontext/signal.go:41.18,41.33 1 0
github.com/davidmdm/xcontext/signal.go:42.3,42.9 1 0
github.com/davidmdm/xcontext/signal.go:45.2,45.20 1 0
github.com/davidmdm/xcontext/signal.go:52.45,54.2 1 1
github.com/davidmdm/xcontext/signal.go:56.49,57.77 1 1
github.com/davidmdm/xcontext/signal.go:57.77,59.3 1 1
github.com/davidmdm/xcontext/signal.go:60.2,60.12 1 1

Manually processed:

mode: set
github.com/davidmdm/xcontext/signal.go:12.123,23.12 4 1
github.com/davidmdm/xcontext/signal.go:23.12,27.10 3 1
github.com/davidmdm/xcontext/signal.go:28.26,30.10 2 1
github.com/davidmdm/xcontext/signal.go:31.24,31.24 0 1
github.com/davidmdm/xcontext/signal.go:32.15,32.15 0 1
github.com/davidmdm/xcontext/signal.go:35.3,35.19 1 1
github.com/davidmdm/xcontext/signal.go:38.2,40.18 2 1
github.com/davidmdm/xcontext/signal.go:40.18,41.18 1 1
github.com/davidmdm/xcontext/signal.go:41.18,41.33 1 1
github.com/davidmdm/xcontext/signal.go:42.3,42.9 1 1
github.com/davidmdm/xcontext/signal.go:45.2,45.20 1 1
github.com/davidmdm/xcontext/signal.go:52.45,54.2 1 1
github.com/davidmdm/xcontext/signal.go:56.49,57.77 1 1
github.com/davidmdm/xcontext/signal.go:57.77,59.3 1 1
github.com/davidmdm/xcontext/signal.go:60.2,60.12 1 1
github.com/davidmdm/xcontext/acceptance/main.go:15.13,26.62 5 1
github.com/davidmdm/xcontext/acceptance/main.go:26.62,27.23 1 1
github.com/davidmdm/xcontext/acceptance/main.go:27.23,28.40 1 1
github.com/davidmdm/xcontext/acceptance/main.go:28.41,28.42 0 1
github.com/davidmdm/xcontext/acceptance/main.go:30.3,30.64 1 1
github.com/davidmdm/xcontext/acceptance/main.go:33.2,38.15 4 1
github.com/davidmdm/xcontext/acceptance/main.go:38.15,40.3 1 1
github.com/davidmdm/xcontext/acceptance/main.go:42.2,44.33 2 1

I expect to see all of my coverage taken into account when running go test -cover.

@seankhliao
Copy link
Member

Duplicate of #60182

@seankhliao seankhliao marked this as a duplicate of #60182 Oct 22, 2023
@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Oct 22, 2023
@golang golang locked and limited conversation to collaborators Oct 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants