A new CLion 2019.3 EAP (build 193.4932.12) is now available! Get it from our website, via the Toolbox App, or as a snap package (if you are using Ubuntu). A patch-update for anyone using the previous EAP build will be available shortly.
Code coverage in CLion relies on llvm-cov/gcov integration to perform and show you statements coverage measuring for your code. In general, statements coverage answers the question, "Was this statement executed during the configuration run?". The configuration can be either a unit tests run or a regular configuration run.
How to launch a configuration with coverage?
To get coverage measurement, you have to pass special coverage compile options. There are a few options depending on what compiler you use and what kind of results you expect:
-fprofile-arcs -ftest-coverageor an equivalent
--coverage– for GCC (uses
gcov) and Clang (uses
llvm-cov gcov, gcov-style coverage, which means it will compatible with the gcov tool from version 4.2 of GCC)
-fprofile-instr-generate -fcoverage-mapping– for Clang (uses
llvm-profdata merge / llvm-cov export, a clang’s instrumentation based profiling).
How to read the results
When rerunning the coverage analysis, CLion will ask you how you’d like the results presented:
- Add to active suites – to enrich the current results.
- Replace active suites – to start from scratch.
- Do not apply collected coverage data – to simply ignore the current results.
Click the gutter area to see how many times the line was hit.
Configuration and known issue
A few important known issues are worth mentioning:
- Code coverage doesn’t work with Ninja generator (CPP-17864). We’ll do our best to address this issue before the release.
- Code Coverage is not supported for the remote toolchain (CPP-17709).
- Generate Coverage Report – an action you may be familiar with if you use IntelliJ IDEA – is not available yet (CPP-17710).
Other bugs and requests are linked to the parent ticket, CPP-9678. Please try the EAP build with code coverage support and share your feedback with us!
If you have to work with a lot of new projects in CLion, you may want to simplify the process of configuring CMake Profiles, for example by configuring a common pattern for the CMake generation folder.
You can set the default:
- Generator used in CMake
- Options passed to CMake
- Build type
- Generation path
- Build options
When a new project is started, these default CMake Profiles will be used. Note that currently, this doesn’t apply when File | New CMake Project from Sources is used (CPP-17686).
That’s it for today! The full release notes are available here.
Your CLion Team
The Drive to Develop