-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/go: unclear when packages have missing test coverage with 1.22 #65262
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
Comments
Can you show the output of |
Go1.22_Issues.docx |
@mvdan I am not sure this should be closed for those reasons because the issue is against Go 1.22rc1 and the draft release notes say:
|
That seems to be from https://go-review.googlesource.com/c/go/+/495447, which is for #24570, one of the earlier issues I linked. This seems to be working as intended; the author here doesn't mention any declared functions with bodies, so there aren't any lines to be covered. Although it's hard to tell because they haven't been very clear about what they are actually doing. cc @thanm, perhaps the release notes should be made clearer. I'll reopen the issue for that purpose. |
@mvdan Thanks. I work with the issue author. They are new to Go and this is the first issue they have submitted. :) We'll get the proper details added here soon. |
The end result may turn out to be working-as-intended, but we weren't sure. |
Here is the sample code that is giving the [no test files] as coverage result
Upon executing the following command The package just contains the interface and we are trying to execute the command against the package, we are getting the above said result |
@rashokkumartce thanks for posting the code in question. As @mvdan mentioned earlier, this Go file doesn't contain any executable statements, so we can't really meaningfully express a code coverage percentage for it. Code coverage is (at some abstract level) N / M, where N is the number of statement lines executed when the tests are run, and M is the number of statement lines defined. For this case M is zero, which renders the N/M ratio invalid. If were were to report "mymod/mypack coverage: 0.0% of statements" for this package, this would imply (incorrectly) that the package does contain some executable code and the tests for the package don't trigger the execution of that code, which is definitely not the case for this package. I'll send a CL to tweak the release notes. |
Change https://go.dev/cl/561337 mentions this issue: |
Clarify the section in the "go" command notes that deals with the changes to "go test -cover" for packages without tests, adding a note that if a package has not tests and no executable code, you still get a "package has no test files" diagnostic. Fixes golang#65262. Change-Id: Ie960871f9d5c1a1965090738644eace28fc3e156 Reviewed-on: https://go-review.googlesource.com/c/go/+/561337 Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Chris Hines <[email protected]>
Go version
go1.22rc1 darwin/amd64
Output of
go env
in your module/workspace:What did you do?
Created a go file with a couple of interfaces with some method signatures and a variable declaration only
What did you see happen?
[no test files]
What did you expect to see?
coverage: 0.0% of statements
The text was updated successfully, but these errors were encountered: