I am using gcov and gcovr to generate my code test coverage (the tests are done with google test++). So, I compile with the -ftest-coverage -fprofile-arcs options, and then I run gcovr (which itself runs gcov). However, on my output, I have the cpp files, with a cover of 100%, but also the .h files, even if they do not have executable code, and hence they have a 0% coverage output.
This 0% does not mean anything, and hence, I would like to remove the .h files from the coverage output. I can't find anything about that...
I already try to add : -e "*.h" to the govr options, to exclude files with .h extension, but it doesn't work (it actually excludes everything...).
Does anybody have an idea ??
Thank you !!
I was also struggling with this, now found the right solution. Here an example and way of working:
When you run gcov, use option -o coverage.xml
, then open the file. Find the filename you want to exclude and copy the filename.
Open in your browser following link and copy the entire filename to the part which says: TEST STRING
https://regex101.com/
Now, where it says: REGULAR EXPRESSION, create a regular expression which makes the entire filename BLUE. Make sure this expression does not apply to other files which are needed to show in your coverage report.
Here some basic rules: Usually, for "some characters" you can use ".*"
what has nothing to do with files of type *.cpp, where you want to see the cpp files! So if you want to exclude anything like "<some characters>include<more characters>"
, then you can use ".*include.*"
. This will also exclude some filename like include.cpp
Because the .
has a meaning in regular expressions, use \.
So if you want to exclude "<something>.h"
files, use ".*\.h"
Example what works for me: (exclude include files and the test framework and linux include directory and exclude jenkins files)
Also I want to exclude any cpp file which has the word test, what I can do with ".*test[_-[A-Z|a-z]*\.cpp"
Real life example:
gcovr --xml -e ".*unit_test\.cpp" -e ".*\.h" -e ".*usr/include/.*" -e ".*jenkins.*" -e ".*test[_-|A-Z|a-z]*\.cpp" -o coverage.xml
have fun!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With