Measuring test coverage for plugins broken?

61 views
Skip to first unread message

Edwin Kempin

unread,
Dec 4, 2020, 8:23:09 AM12/4/20
to Repo and Gerrit Discussion
Hi,

Does anyone know how to measure the test coverage of plugin code?

In the past it was possible to get the test coverage for plugin code by
* configuring the plugin as submodule and having its sources in the tree
* running the tools/coverage.sh script

I’m sure that this worked because I used this to inspect the test coverage of the checks plugin back then when we wrote this plugin.

Now I’m trying to do the same for the code-owners plugin.

To make the tools/coverage.sh script run for me I need to add the following 2 lines at the beginning (this I needed to do already back then, just mentioning it here if case anyone else needs this):
shopt -s expand_aliases
source ~/.bash_profile

Running tools/coverage.sh runs all tests (including the code-owners test) and produces a report. The report shows test coverage for the test classes of the code-owners plugin (though with weird 'tmp' paths, see [1]) but test coverage for the code-owners backend classes is missing.

Does anyone see what's wrong?

Thanks,
Edwin

[1] https://imgur.com/vpmInqA

Edwin Kempin

unread,
Dec 4, 2020, 8:32:07 AM12/4/20
to Repo and Gerrit Discussion
While looking at the script, I noticed some issues which I fixed in [1] but it didn't help with the actual issue.

David Ostrovsky

unread,
Dec 5, 2020, 3:21:50 PM12/5/20
to Repo and Gerrit Discussion
I tried to reproduce the problem and created these reproducers: [1],[2]
and filed this issue upstream: [3].

Now that we understand the problem, the solution could be also implemented
in code-owners plugin. I refactored the build to split the source rules to match
the java packages: [4]. Now test coverage works as expected: [5].

BTW, you shouldn't actually need custom `tools/coverage.sh` script.
Bazel is shipping lcov merge utility. Just call the coverage command
like this:

  $ bazel coverage --test_output=all \
    plugins/code-owners/... \
    --coverage_report_generator=@bazel_tools//tools/test:coverage_report_generator \
    --combined_report=lcov

This should produce merged coverage.dat file:

[...]
INFO: LCOV coverage report is located at /home/davido/.cache/bazel/_bazel_davido/5c01f4f713b675540b8b424c5c647f63/execroot/gerrit/bazel-out/_coverage/_coverage_report.dat
 and execpath is bazel-out/_coverage/_coverage_report.dat

$ ls -all bazel-out/_coverage/_coverage_report.dat
-r-xr-xr-x 1 davido users 300658 Dec  5 19:59 bazel-out/_coverage/_coverage_report.dat

Edwin Kempin

unread,
Dec 9, 2020, 8:53:58 AM12/9/20
to David Ostrovsky, Repo and Gerrit Discussion
Hi David,

Sorry for replying late, but I was OOO for a few days.

Thank you so much David, you are the best!
With your change, generating the test coverage works for me too!
Do you mind if I split your change into smaller chunks so that I can apply it piece by piece?
These changes likely break our internal build and it's safer for me to do this step by step.

Thanks, Edwin


--
--
To unsubscribe, email repo-discuss...@googlegroups.com
More info at http://groups.google.com/group/repo-discuss?hl=en

---
You received this message because you are subscribed to the Google Groups "Repo and Gerrit Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to repo-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/repo-discuss/a4f87614-cb76-4183-9819-6ce979a8db5bn%40googlegroups.com.

David Ostrovsky

unread,
Dec 9, 2020, 9:21:14 AM12/9/20
to Repo and Gerrit Discussion
Edwin Kempin schrieb am Mittwoch, 9. Dezember 2020 um 14:53:58 UTC+1:
Hi David,

Sorry for replying late, but I was OOO for a few days.

Thank you so much David, you are the best!
With your change, generating the test coverage works for me too!

You are wellcome!
 
Do you mind if I split your change into smaller chunks so that I can apply it piece by piece?

Sure, feel free to split that change. Thanks.
Reply all
Reply to author
Forward
0 new messages