0

I am using gcovr for determining line and branch coverage of my C++ code. However, there are some classes that can't be tested (due to dependencies to the OS) and therefore have 0 coverage. I would like to exclude those from my reports.

I have added the GCOV_EXCL_START (and matching GCOV_EXCL_STOP) comments to the start and end of the file. This successfully excludes the code between the comments from branch coverage, but gcovr still reports 0 line coverage for those files.

/** HEADER INCLUDES **/

/*
 * This file is excluded from coverage generation. It attempts to create CANSocket and ZMQSocket objects, which are
 * themself untestable. Therefore, this class is also untestable and cannot be covered.
 */
// GCOV_EXCL_START

/** CODE **/

// GCOV_EXCL_STOP

Since the exclusion markers are undocumented (I only found out about them through a comment somewhere on stackoverflow), I don't know whether they're supposed to just exclude branch coverage or should exclude line coverage as well.

I hope someone here can tell me:

  1. Why line coverage isn't covered by these exclusion markers, and if that is intentional, why?
  2. How I might exclude the files from line coverage anyway, preferably without having to specify them in the gcovr command as excluded.
Maarten
  • 31
  • 4
  • Hmm, this seems like a bug – exclusion markers should exclude all coverage information. Could you perhaps create a reproducible example? If you want to exclude whole files you'll have to use the `--exclude` command line option, or install the development version of gcovr and move the filters into the config file. See also the docs of gcovr's master branch: https://gcovr.com/en/master/guide.html#configuration-files – amon Sep 17 '19 at 13:14
  • I'd prefer to exclude files from coverage using comments in the file itself. That way, you can immediately see in the file itself why it isn't included in the coverage calculation, instead of having to find e.g. the gcovr command in the Jenkinsfile. What exactly would you expect in a reproducible example? Basically, if you replace the `/** CODE **/` comment with actual code and run gcovr, you'll see that the coverage (in the output xml file) does not say anything about branches, but does report 0 line coverage. – Maarten Sep 18 '19 at 16:03

0 Answers0