From 30f0886e75a8dc18ca4a0ca7394a8314c729701e Mon Sep 17 00:00:00 2001 From: Moaaz Assali <66834697+moaazassali@users.noreply.github.com> Date: Sat, 6 Jul 2024 23:51:29 +0400 Subject: [PATCH] added code coverage test into linux gcc workflow --- .github/workflows/linux.yml | 9 +++++++++ CMakeLists.txt | 11 ++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 112566d..a14b2c6 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -30,6 +30,7 @@ jobs: - os: ubuntu-latest c_compiler: gcc cpp_compiler: g++ + build_type: Coverage - os: ubuntu-latest c_compiler: clang cpp_compiler: clang++ @@ -65,3 +66,11 @@ jobs: # Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail run: ctest --build-config ${{ matrix.build_type }} + + - name: Code Coverage + if: matrix.c_compiler == 'gcc' + working-directory: ${{ steps.strings.outputs.build-output-dir }} + run: | + sudo apt-get update + sudo apt-get install -y gcovr + gcovr -r .. -f ../src \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 03814df..1a71310 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,4 +56,13 @@ target_include_directories(${PROJECT_NAME}-tests list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/dependencies/doctest/scripts/cmake") include(doctest) -doctest_discover_tests(${PROJECT_NAME}-tests) \ No newline at end of file +doctest_discover_tests(${PROJECT_NAME}-tests) + + +# ======================================== +# Code Coverage +# ======================================== +if (CMAKE_BUILD_TYPE STREQUAL "Coverage") + SET(CMAKE_CXX_FLAGS "-g -O0 --coverage") + SET(CMAKE_C_FLAGS "-g -O0 --coverage") +endif () \ No newline at end of file