I have a c++ project that uses CMake for generating makefiles. I have added a custom target to run the code coverage as follows:
add_custom_target(
coverage
COMMAND
lcov --rc lcov_branch_coverage=1 --capture --directory
${CMAKE_SOURCE_DIR} --output-file
${CMAKE_BINARY_DIR}/${PROJECT_NAME}_coverage.info --no-external
COMMAND
genhtml --branch-coverage
${CMAKE_BINARY_DIR}/${PROJECT_NAME}_coverage.info --output-directory
${CMAKE_BINARY_DIR}/coverage_report --title
"${PROJECT_NAME} code coverage report" --show-details --legend
COMMAND
echo
"Covverage report in ${CMAKE_BINARY_DIR}/coverage_report/index.html")
(earlier in the project I set the right compilation and linking flags and add different tests using add_test
). When I run make
, make test
, make coverage
I get the code coverage report properly. Now I am integrating this into a CI/CD and I want to check the coverage % of the resulting code coverage analysis to be above a threshold. If it is not above I want to fail the pipeline. Is there a way to run some process that will exit with an error code if the coverage is not above a given threshold?