Skip to content

Add support for building with code coverage instrumentation

Hugo Hromic requested to merge add-coverage into dev
  • When configuring the build, use -DSOLARUS_CODE_COVERAGE=ON to enable.
  • For accurate coverage results, also use -DCMAKE_BUILD_TYPE=Debug

Quick Guide

The gcov library should be pre-installed with your compiler.

To generate the HTML coverage report, you need to install the Gcovr utility.

# configure build with new option (disable GUI for faster builds)
mkdir build
cmake -B build -DCMAKE_BUILD_TYPE=Debug -DSOLARUS_CODE_COVERAGE=ON -DSOLARUS_GUI=OFF
make -C build -j$(nproc)
make -C build -j$(nproc) test

# generate HTML coverage report with Gcovr
mkdir coverage
gcovr --html --html-details \
      --exclude-unreachable-branches --exclude-throw-branches \
      --root $PWD --object-directory $PWD/build \
      --exclude 'build/*' --exclude 'gui/*' --exclude 'tests/*' \
      --output coverage/coverage.html

The main coverage report index is now in coverage/coverage.html.

Merge request reports

Loading