Skip to content

CMake functions to provide C++ code coverage reports in an easy way using OpenCppCoverage.

License

Notifications You must be signed in to change notification settings

ekcoh/cpp-coverage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cpp-coverage

Introduction

This project provides CMake functions to simplify running C++ tests with code coverage reports generated by OpenCppCoverage.

Usage

In order to use cpp-coverage to simplify usage of OpenCppCoverage, all you need to do is to make sure cpp-coverage is available to your build by e.g. FetchContent or ExternalProject_Add followed by add_subdirectory and finally use cpp_coverage_add_test function to augment the regular cmake add_test function with coverage measurements based on existing test binary targets. The utility functions provided by this repository will create custom targets to generate generate coverage reports (e.g. HTML) based on merged .cov files generated while running CTest. Coverage reports default to aggregated project coverage but additional options exist to for example generate reports per test target or aggregate a global "super-build" coverage report.

See documentation of CMake functions in cmake/cpp_coverage.cmake for a complete list of supported options.

See documentation of ReportGenerator for documentation on how to customize coverage reports outside what is supported by OpenCppCoverage. ReportGenerator is activated by setting CPP_COVERAGE_ENABLE_REPORT_GENERATOR to ON.

Usage with existing test frameworks

Examples provided in this project are using Google Test in combination with CTest but also showcases usage with custom solutions. Note that CTest support is similar to CMake add_testcommand. Adding tests via e.g. gtest_discover_tests(...) is currently not supported but might be added in the future.

For complete examples, see examples folder. Examples are not built by default and requires CPP_COVERAGE_BUILD_EXAMPLES to be set to ON.

See OpenCppCoverage documentation for details on how to use and integrate in CI etc.

License

This project is released under the MIT license, see LICENSE. This basically means you can do whatever you want with this project as long as you provide the original license and copyright information with your own project distribution.

Note that utilized dependencies such as OpenCppCoverage, Google Test and ReportGenerator are subject of their respective licenses and terms and are not distributed as part of this software.

About

CMake functions to provide C++ code coverage reports in an easy way using OpenCppCoverage.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages