diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4f722bd..4e9951c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,18 +17,17 @@ jobs: - name: Install dependencies run: | sudo apt-get update - sudo apt-get install -y cmake clang-format clang-tidy-20 libsdl2-dev protobuf-compiler + sudo apt-get install -y cmake clang-format clang-tidy-20 libsdl2-dev protobuf-compiler gcovr - name: Check Code Formatting run: | find src include tests -type f \( -name "*.cpp" -o -name "*.hpp" -o -name "*.c" -o -name "*.h" \) | xargs clang-format --dry-run -Werror - name: Configure CMake - run: cmake -B build -DCMAKE_BUILD_TYPE=Release + run: cmake -B build -DCMAKE_BUILD_TYPE=Release -DNEURON_IDE_ENABLE_COVERAGE=ON - name: Build run: cmake --build build --config Release - - name: Run Tests - working-directory: build - run: ctest --output-on-failure -C Release + - name: Run Tests & Check Coverage + run: cmake --build build --target coverage diff --git a/CMakeLists.txt b/CMakeLists.txt index 23a1575..d7151dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") include(Dependencies) include(CompilerWarnings) include(StaticAnalysis) +include(Coverage) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) diff --git a/cmake/Coverage.cmake b/cmake/Coverage.cmake new file mode 100644 index 0000000..4219d95 --- /dev/null +++ b/cmake/Coverage.cmake @@ -0,0 +1,40 @@ +# cmake/Coverage.cmake + +option(NEURON_IDE_ENABLE_COVERAGE "Enable code coverage reporting" OFF) + +if(NEURON_IDE_ENABLE_COVERAGE) + find_program(GCOVR_PATH gcovr) + + if(NOT GCOVR_PATH) + message(FATAL_ERROR "gcovr not found! Aborting configuration...") + endif() + + if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") + message(STATUS "Adding coverage compiler flags") + add_compile_options(--coverage) + add_link_options(--coverage) + else() + message(FATAL_ERROR "Code coverage is only supported with GCC or Clang") + endif() + + set(COVERAGE_DIR "${CMAKE_BINARY_DIR}/coverage") + + add_custom_target(coverage + COMMAND ${CMAKE_COMMAND} -E make_directory ${COVERAGE_DIR} + COMMAND ctest --output-on-failure + COMMAND ${GCOVR_PATH} + --root ${CMAKE_SOURCE_DIR} + --exclude ".*_deps.*" + --exclude ".*tests.*" + --exclude ".*test.*" + --exclude ".*protoFiles.*" + --exclude ".*pb.*" + --exclude ".*\\.hpp" + --fail-under-line 60 + --print-summary + --html-details ${COVERAGE_DIR}/index.html + --xml ${COVERAGE_DIR}/coverage.xml + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + COMMENT "Running tests and generating code coverage report..." + ) +endif()