Search code examples
cunit-testinggcovlcov

Gcov doesn't handle correctly comments and multiple line sentences


I am using lcov/gcov to measure test coverages in a project.

However, the test coverage report includes some lines signaled as unhitted that shouldn't be there. For example:

enter image description here

Comment lines, function definitions splitted across two lines, opening brackets, etc are counted towards total coverage as not covered.

How can I instruct lcov/gcov to ignore such lines?


Solution

  • Finally, I solved the issue. Looking at gcov man page (https://linux.die.net/man/1/gcov) I found that gcov works only on code compiled with GCC . It is not compatible with any other profiling or test coverage mechanism.

    Default C compiler in my system was ClangC. Setting gcc as compiler when calling cmake this way

    $ cmake . -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=/usr/bin/gcc

    solved the problem.