From c54cdfbb5b75583da6c6586e88cd82c440cc8ba8 Mon Sep 17 00:00:00 2001 From: msiverback Date: Mon, 17 Oct 2022 08:42:57 +0200 Subject: [PATCH] Enable coverage and add Howto for coverage Updated CMakeLists.txt to enable coverage. Updated instructions with howto for coverage and also a separate set of instructions how to run during a TDD cycle with coverage. --- cpp/CMakeLists.txt | 4 ++-- cpp/README.md | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 26325069..4c36e3ff 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -28,8 +28,8 @@ endif() # Bring the populated content into the build add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR}) -# uncomment this line to enable coverage measurements using gcov -# set(CMAKE_CXX_FLAGS "--coverage") +# comment this line to disable coverage measurements using gcov +set(CMAKE_CXX_FLAGS "--coverage") enable_testing() add_subdirectory(src) diff --git a/cpp/README.md b/cpp/README.md index 8c9b61e0..cfe15691 100644 --- a/cpp/README.md +++ b/cpp/README.md @@ -49,6 +49,18 @@ The `GildedRose.cc` file, i.e. the code under test, is identical in all four var $ ctest -VV --tests-regex Catch2Approval +## How to run with test coverage +1. go to build directory +2. Run: + $ lcov --directory ./ --capture --output-file ../lcov.info -rc lcov_branch_coverage=1 +3. in bottom right corner of VS Code press "Watch" +3. Coverage will now be visible in VSCode. + +## How to run during a typical TDD cycle + $ cmake --build . + $ ctest -VV --tests-regex GildedRoseGoogletestUnitTests + $ lcov --directory ./ --capture --output-file ../lcov.info -rc lcov_branch_coverage=1 + ## How to build and run tests using the [CLion IDE](https://www.jetbrains.com/clion/) 1. Start CLion