Skip to content
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/cover: go test -cover and go tool cover -func don't give the same results #20515

Closed
dlespiau opened this issue May 28, 2017 · 2 comments
Closed

Comments

@dlespiau
Copy link
Contributor

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

go version go1.8 linux/amd64

What did you do?

I used the github.com/dlespiau/x86db package for the example below, but the same issue can be reproduced on other packages I have around and so assuming it's a general problem:

$ go test -coverprofile=profile.cov
PASS
coverage: 26.3% of statements

Whereas:

$ go tool cover -func=profile.cov | tail -1
total:							(statements)		26.1%

Not that I've noticed larger differences, up to 1% on other packages.

What did you expect to see?

I expect to see the same coverage number.

What did you see instead?

Two different coverage percentages.

@ALTree ALTree changed the title go test -cover and go tool cover -func don't give the same results cmd/cover: go test -cover and go tool cover -func don't give the same results May 28, 2017
@ALTree ALTree added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 28, 2017
@gopherbot
Copy link

CL https://golang.org/cl/44337 mentions this issue.

@JayNakrani
Copy link
Contributor

JayNakrani commented May 28, 2017

Found the issue.

cmd/cover/func.go initializes total to 1 for each function. Whereas testing/cover.go only does it once. So if your code has lots of functions with total==0, then discrepancy is going to be high.

http://golang.org/cl/44337 should fix that.

@JayNakrani JayNakrani added this to the Go1.9Maybe milestone May 28, 2017
@JayNakrani JayNakrani removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 28, 2017
dlespiau pushed a commit to dlespiau/covertool that referenced this issue May 29, 2017
This command computes the coverage percentage of the whole profile.

This is different from what go tool cover -func does because of this
bug: golang/go#20515

Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
@golang golang locked and limited conversation to collaborators Jun 2, 2018
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

4 participants