diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 00000000..29adcbac --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,48 @@ +name: Coverage + +on: + push: + branches: + - main + + pull_request: + branches: + - main + workflow_dispatch: + +jobs: + coverage: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install LCov and dependencies + run: | + sudo apt-get update -q + sudo apt-get install -q -y lcov libhdf5-dev libboost-all-dev + git clone https://github.com/catchorg/Catch2.git + cd Catch2 + git checkout "v3.5.3" + cmake -Bbuild -H. -DBUILD_TESTING=OFF + sudo cmake --build build/ --target install + + - name: Configure + run: cmake --preset=ci-coverage + + - name: Build + run: cmake --build build/coverage -j 2 + + - name: Test + working-directory: build/coverage + run: ctest --output-on-failure --no-tests=error -j 2 + + - name: Process coverage info + run: cmake --build build/coverage -t coverage + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v4 + with: + file: build/coverage/coverage.info + fail_ci_if_error: true + token: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file diff --git a/CMakePresets.json b/CMakePresets.json index 0ff72039..6d802390 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -120,6 +120,19 @@ "CMAKE_SHARED_LINKER_FLAGS_COVERAGE": "--coverage" } }, + { + "name": "coverage-darwin", + "binaryDir": "${sourceDir}/build/coverage", + "inherits": "ci-darwin", + "hidden": true, + "cacheVariables": { + "ENABLE_COVERAGE": "ON", + "CMAKE_BUILD_TYPE": "Coverage", + "CMAKE_CXX_FLAGS_COVERAGE": "-Og -g --coverage", + "CMAKE_EXE_LINKER_FLAGS_COVERAGE": "--coverage", + "CMAKE_SHARED_LINKER_FLAGS_COVERAGE": "--coverage" + } + }, { "name": "ci-coverage", "inherits": ["coverage-linux", "dev-mode"], diff --git a/cmake/coverage.cmake b/cmake/coverage.cmake index c89cc161..6c4b03e2 100644 --- a/cmake/coverage.cmake +++ b/cmake/coverage.cmake @@ -7,14 +7,14 @@ set( lcov -c -q -o "${PROJECT_BINARY_DIR}/coverage.info" -d "${PROJECT_BINARY_DIR}" - --include "${PROJECT_SOURCE_DIR}/*" + --include "${PROJECT_SOURCE_DIR}/src/*" CACHE STRING "; separated command to generate a trace for the 'coverage' target" ) set( COVERAGE_HTML_COMMAND - genhtml --legend -f -q + genhtml --legend -q "${PROJECT_BINARY_DIR}/coverage.info" -p "${PROJECT_SOURCE_DIR}" -o "${PROJECT_BINARY_DIR}/coverage_html"