Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
40 changes: 40 additions & 0 deletions cmake/Coverage.cmake
Original file line number Diff line number Diff line change
@@ -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()
Loading