-
-
Notifications
You must be signed in to change notification settings - Fork 668
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
It's not possible to generate coverage for testonly libraries. #2786
Comments
I suspect this to be true as well. I think a good next step would be to see the concrete details of this is by uploading it as a PR. That way we can patch it into a few projects and see the implications. WDYT? |
I've got it patched into a fairly enormous go mono repo. Tests still passed. |
Walking back through the repo history, it looks like the exclusion of Is there precedent for this in other languages? If other languages instrument |
I've spent > 30 minutes grokking bazelbuild+testonly issues, but nothing that interesting (other than bazel-contrib/bazel-gazelle#513). FWIW I'll get the patch into our mono repo this evening, and see how it soaks. |
Just curious: why is it useful to have coverage info for You mentioned bazelbuild/bazel#12176, but that seems like a limitation of |
I can provide an example of this. I used to work on a database. We had an in memory implementation of our server (with a convenient way to get an object that implemented the client interface). That object was testonly, but was also a part of our contract to consumers. Therefore we wanted to validate that it had high levels of test coverage so people wouldn't be surprised by silly mistakes. |
+1, we have tests for our test_utils.
…On Fri, 15 Jan 2021 at 12:43, Andrew Z Allen ***@***.***> wrote:
I can provide an example of this. I used to work on a database. We had an
in memory implementation of our server (with a convenient way to get an
object that implemented the client interface). That object was testonly,
but was also a part of our contract to consumers. Therefore we wanted to
validate that it had high levels of test coverage so people wouldn't be
surprised by silly mistakes.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#2786 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACG3UU2LZI6ZFZGXBQIVSLS2BWCJANCNFSM4WCWN5AA>
.
|
We have a fake implementation of Zookeeper used to trigger race conditions that could occur in production. It's complex enough that it needs its own tests. I think I would also emphasize that all code needs to be production quality code. We code review tests for their quality, as well as the code they are actually testing. Specific bad examples are line-hitter tests, that get 100% coverage, but don't validate a single condition. If you are providing a fake for someone to validate their production code, that fake needs to be robust, otherwise you are not building that production code on a good foundation. |
Makes sense, thanks all for good examples. I'll merge #2787. A workaround for this would be to define two In any case, it should be possible to gather coverage data for |
We also have wrappers on top of the build to enforce coverage limits. The just enables the ability to generate coverage. Not the requirement nor enforcement. |
As a final comment, I present With somewhat extensive tests. |
What version of rules_go are you using?
v0.24.9
What version of gazelle are you using?
bazel-contrib/bazel-gazelle@9c04579
What version of Bazel are you using?
3.7.0
Does this issue reproduce with the latest releases of all the above?
Yes.
What operating system and processor architecture are you using?
OS-X Catalina / Debian Buster, x86_64.
Any other potentially useful information about your toolchain?
What did you do?
bazel coverage :go_default_test
for ago_library
marked withtestonly = True
.What did you expect to see?
Coverage file
go_default_test/coverage.dat
generated.What did you see instead?
Test pass but no coverage file was generated.
Discussion
This is related to the discussion in bazelbuild/bazel#12176, especially bazelbuild/bazel#12176 (comment):
This is exactly the issue we are running into. We had noticed test helper code was slipping into production code, including some references to
testing.T
. We refactored and marked these libraries astestonly
. Only afterwards did we notice that coverage was not being generated.I've got a PR for this fix, which we are testing locally in our mono-repo, but I wonder if it won't be acceptable to turn coverage on for any
testonly
package, rather we need someWORKSPACE
option to enable this.However, I suspect there is a high correlation between those who have the due diligence to mark packages as
testonly
, and those who want coverage for these packages.The text was updated successfully, but these errors were encountered: