Exclusion Markers
You can exclude parts of your code from coverage metrics.
If
GCOVR_EXCL_LINEappears within a line, that line is ignored.If
GCOVR_EXCL_STARTappears within a line, all following lines (including the current line) are ignored until aGCOVR_EXCL_STOPmarker is encountered.If
GCOVR_EXCL_FUNCTIONin the line of the function definition but not in front of the definition, the lines of the function are ignored. This marker needs thegcovJSON format version 2 which is generated bygcc-14and newer. If the needed info isn't available a warning is printed if the tag is found. Also a warning is printed if no function is defined at the tag location. See also--exclude-function.If
GCOVR_EXCL_BR_*markers are used the same exclusion rules apply as above, with the difference being that they are only taken into account for branch coverage.If
GCOVR_EXCL_BR_SOURCEappears within a line, the branches which have one of the block ids of the current line as destination block are excluded from the coverage. This can be used e.g. in adefaultbranch which is used for error handling to exclude the source branch from the coverage.If
GCOVR_EXCL_BR_WITHOUT_HIT: uncovered/totalappears within a line, the uncovered branches are ignored, e.g.GCOVR_EXCL_BR_WITHOUT_HIT: 2/6will exclude the 2 uncovered branches out of 6 branches in the line. If the uncovered or total branches doesn't match the branches in the line a error is logged and nothing is excluded.
Instead of GCOVR_*,
the markers may also start with GCOV_* or LCOV_*.
However, start and stop markers must use the same style.
The prefix is configurable with the option --exclude-pattern-prefix.
The excluded region not includes the line with the stop marker:
code
code
excluded // GCOVR_EXCL_START
still excluded
...
still excluded
NOT excluded // GCOVR_EXCL_STOP
code
code
In the excluded regions, any coverage is excluded.
Added in version 8.0: If --verbose is used the exclusion ranges are logged.
Added in version 8.0: Comment GCOVR_EXCL_BR_SOURCE.
Added in version 8.4: Comment GCOVR_EXCL_BR_WITHOUT_HIT: uncovered/total.