-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
testing: Coverage() function doesnt work for go 1.20+ #59590
Comments
CC @thanm |
Thanks for the report. |
Awesome thanks! In addition, it would be great if that value Coverage() returns is the same as the one that gets sent to the coverage report after the test. The previous implementation did not calculate this value the same way so the value returned differed from the coverage report (% of blocks vs % of statements). We use this value as a pseudo way to enforce test coverage. Would love to see this more integrated into the tools in the future to do this in a more official way. |
Thanks. I'll put that issue on my list.
Cheers, Than
…On Wed, Apr 26, 2023 at 2:08 PM Simon Kotwicz ***@***.***> wrote:
@thanm <https://github.com/thanm> may not be related but Go 1.20 broke
overall code coverage for a lot of people as per #24570 (comment)
<#24570 (comment)>
—
Reply to this email directly, view it on GitHub
<#59590 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AC5WC3B4CAYIG3VKKPFIN63XDFQC5ANCNFSM6AAAAAAW4GMIDU>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Change https://go.dev/cl/495450 mentions this issue: |
Change https://go.dev/cl/495449 mentions this issue: |
Add a new function runtime/coverage.snapshot(), which samples the current values of coverage counters in a running "go test -cover" binary and returns percentage of statements executed so far. This function is intended to be used by the function testing.Coverage(). Updates #59590. Change-Id: I861393701c0cef47b4980aec14331168a9e64e8e Reviewed-on: https://go-review.googlesource.com/c/go/+/495449 Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
Hi! I was expecting this to be backported to 1.20.5 but it was not. I saw the commit is in |
From https://github.com/golang/go/wiki/MinorReleases: Our default decision should always be to not backport, but fixes for security issues, serious problems with no workaround, and documentation fixes are backported to the most recent two release branches, if applicable to that branch Generally speaking "serious problem" means your program is crashing or computing incorrect results, that sort of thing. I would be surprised in this case if the release team were to approve a backport given the nature of the bug. Sorry about that. |
So, testing.Coverage() is returning 0 always, is not that an incorrect computing result?. My program is not crashing but my test suite is. So I need the build -cover feature introduced in 1.20 but can't break my test suite. I was just asking if I can expect this to be fixed in 1.20.x, otherwise I will wait to 1.21 |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Calling testing.Coverage() always returns 0.0. Looking at the source, this function has not been updated to the new coverage2 system.
What did you expect to see?
testing.Coverage() should return the percent of code coverage for the current unit test.
What did you see instead?
Always returns 0
The text was updated successfully, but these errors were encountered: