cmakecatchcoverage

November 18, 2019 ยท View on GitHub

Integration of CMake, Catch and CMake CodeCoverage module for C++ code. (CMake CodeCoverage depends on: gcov, gcovr, genhtml, lcov.)

Setup

install test build environment tools (Ubuntu)

./setup.sh

Usage

test build and test execution (with junit format .xml result piping into build/unit_test_result.xml, without coverage analysis)

cd build/
cmake ..
make unit_tests
./unit_tests -r junit > unit_test_result.xml

test build, test execution (with coverage analysis) and coverage observation

cd build/
cmake .. -DENABLE_CODE_COVERAGE=on
make unit_tests_coverage
xdg-open ./unit_tests_coverage/index.html

Clare Macrae's extra notes

Generating branch coverage

Based on this question, you need to have the following lines enabled in your ~/.lcovrc file:

genhtml_branch_coverage = 1
lcov_branch_coverage = 1

On a Mac, with lcov installed via brew, you will want to look at /usr/local/etc/lcovrc, not /etc/lcovrc

See the reference docs: lcovrc - lcov configuration file.

Excluding Catch2 test macros from the branch coverage

Add this to your ~/.lcovrc file:

lcov_excl_br_line = LCOV_EXCL_BR_LINE|CHECK|REQUIRE