Skip to content

Commit

Permalink
Merge pull request #62 from benvenutti/feature/add-code-coverage
Browse files Browse the repository at this point in the history
Feature/add code coverage
  • Loading branch information
benvenutti authored Sep 3, 2024
2 parents 6a8ef07 + d1881fd commit 75187ea
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 5 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ jobs:

- name: Configure
working-directory: ${{github.workspace}}/build
run: cmake -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} ..
run: cmake -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DBUILD_TESTS=ON ..

- name: Build
working-directory: ${{github.workspace}}/build
run: cmake --build . --config ${{ matrix.build_type }}
run: cmake --build . --config ${{ matrix.build_type }} --verbose

- name: Test
working-directory: ${{github.workspace}}/build
run: ctest -C ${{ matrix.build_type }} -VV .
run: ctest --build-config ${{ matrix.build_type }} --extra-verbose .
65 changes: 65 additions & 0 deletions .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: coverage

on: [push]

jobs:
coverage:
runs-on: ubuntu-22.04

steps:
- name: Check out repository code
uses: actions/checkout@v4

- name: Install Qt
uses: jurplel/install-qt-action@v4
with:
version: '6.5.*'
target: 'desktop'

- name: Install coverage-related dependencies
run: sudo apt-get install -o Acquire::Retries=3 lcov

- name: Create build directory
run: cmake -E make_directory ${{runner.workspace}}/build

- name: Configure
working-directory: ${{runner.workspace}}/build
run: cmake $GITHUB_WORKSPACE \
-DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=ON -DCODE_COVERAGE=ON

- name: Build
working-directory: ${{runner.workspace}}/build
run: cmake --build . --config Debug

- name: Gather baseline coverage
working-directory: ${{runner.workspace}}/build
run: lcov --directory . --capture --initial --output-file baseline.info

- name: Test
working-directory: ${{runner.workspace}}/build
run: ctest --build-config Debug --extra-verbose .

- name: Gather test coverage
working-directory: ${{runner.workspace}}/build
run: lcov --directory . --capture --output-file test.info

- name: Generate coverage report
working-directory: ${{runner.workspace}}/build
run: |
# combine baseline and test coverage data:
lcov -a baseline.info -a test.info --output-file coverage.info
# filter paths from report:
lcov --remove coverage.info '/usr/include/*' --output-file coverage.info
lcov --remove coverage.info '*/catch2-src/*' --output-file coverage.info
lcov --remove coverage.info '*/build/*' --output-file coverage.info
lcov --remove coverage.info '*/Qt/*' --output-file coverage.info
# generate the HTML files:
genhtml --demangle-cpp -o coverage coverage.info
- name: Upload results to Coveralls
uses: coverallsapp/github-action@master
with:
path-to-lcov: ${{runner.workspace}}/build/coverage.info
github-token: ${{ secrets.GITHUB_TOKEN }}
18 changes: 16 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,21 @@ project(
LANGUAGES CXX
)

# modules:

include(CMakeDependentOption)
include(FetchContent)

# project options:

option(BUILD_TESTS "Build tests" ON)
cmake_dependent_option(CODE_COVERAGE "Enable code coverage" OFF "BUILD_TESTS" OFF)

# 3rd party dependencies:

find_package(Qt6 6.5 COMPONENTS Widgets REQUIRED)

if(BUILD_TESTS)
include(FetchContent)

FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
Expand Down Expand Up @@ -61,6 +67,14 @@ else()
# optimization levels:
$<$<CONFIG:RELEASE>:-O3>
$<$<CONFIG:DEBUG>:-O0>

# coverage:
$<$<BOOL:${CODE_COVERAGE}>:-coverage>
)

add_link_options(
# coverage:
$<$<BOOL:${CODE_COVERAGE}>:-coverage>
)
endif()

Expand Down

0 comments on commit 75187ea

Please sign in to comment.