Skip to content

Commit fcdbad0

Browse files
authored
Merge pull request #38 from Rookfighter/feature/add-code-coverage
Implement coverage reporting in CI
2 parents 14a29da + f9220fc commit fcdbad0

File tree

3 files changed

+47
-7
lines changed

3 files changed

+47
-7
lines changed

.github/workflows/cmake.yml

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,41 @@ on:
88

99
jobs:
1010
format:
11-
name: Check C++ Code Format
11+
name: Check Code Format
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v4
1515
- name: Check Format
1616
run: 'find test/ examples/ include/ -iname "*.h" -o -iname "*.cpp" -print0 | xargs -0 clang-format --dry-run --Werror'
17+
coverage:
18+
name: Generate Code Coverage
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v4
22+
with:
23+
submodules: recursive
24+
- name: Install LCOV
25+
run: |
26+
sudo apt update
27+
sudo apt install -y lcov
28+
- name: Configure
29+
run: cmake -S . -B ${{runner.workspace}}/build -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=ON -DGENERATE_COVERAGE=ON -DINICPP_CXX_STANDARD=17
30+
- name: Build
31+
run: cmake --build ${{runner.workspace}}/build --config Debug
32+
- name: Test
33+
run: ctest -C Debug --output-on-failure --test-dir ${{runner.workspace}}/build
34+
- name: Generate Coverage
35+
run: |
36+
lcov --capture --directory ${{runner.workspace}}/build --include '*/inicpp.h' --output-file ${{runner.workspace}}/lcov.info
37+
lcov --list ${{runner.workspace}}/lcov.info
38+
- name: Codecov
39+
uses: codecov/codecov-action@v4
40+
env:
41+
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}
42+
with:
43+
file: ${{runner.workspace}}/lcov.info
44+
verbose: true
45+
fail_ci_if_error: true
1746
build:
1847
name: "${{matrix.config.name}} C++${{matrix.cxx}}"
1948
runs-on: ${{matrix.config.os}}
@@ -46,8 +75,8 @@ jobs:
4675
with:
4776
submodules: recursive
4877
- name: Configure
49-
run: cmake -S . -B ${{runner.workspace}}/build -DCMAKE_BUILD_TYPE=${{matrix.config.build_type}} -DBUILD_TESTS=True -DBUILD_EXAMPLES=True -DINICPP_CXX_STANDARD=${{matrix.cxx}}
78+
run: cmake -S . -B ${{runner.workspace}}/build -DCMAKE_BUILD_TYPE=${{matrix.config.build_type}} -DBUILD_TESTS=ON -DBUILD_EXAMPLES=ON -DINICPP_CXX_STANDARD=${{matrix.cxx}}
5079
- name: Build
5180
run: cmake --build ${{runner.workspace}}/build --config ${{matrix.config.build_type}}
5281
- name: Test
53-
run: ctest -C ${{matrix.config.build_type}} --test-dir ${{runner.workspace}}/build
82+
run: ctest -C ${{matrix.config.build_type}} --output-on-failure --test-dir ${{runner.workspace}}/build

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
lcov.info
12
build/
23
Testing/
34
.project

CMakeLists.txt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,22 @@ project(inifile-cpp)
1111
include(CTest)
1212

1313
set(INICPP_CXX_STANDARD "11" CACHE STRING "C++ standard to use when building tests & examples.")
14+
option(GENERATE_COVERAGE "Enable generating code coverage" OFF)
15+
option(BUILD_TESTS "Enable building unit tests" OFF)
16+
option(BUILD_EXAMPLES "Enable building example applications" OFF)
1417

15-
SET(CMAKE_CXX_STANDARD ${INICPP_CXX_STANDARD})
16-
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
18+
set(CMAKE_CXX_STANDARD ${INICPP_CXX_STANDARD})
19+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1720

1821
if(CMAKE_COMPILER_IS_GNUCXX)
19-
set(CMAKE_CXX_FLAGS "-Wall -Wextra")
22+
add_compile_options(-Wall -Wextra)
2023
endif(CMAKE_COMPILER_IS_GNUCXX)
2124

2225
if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
23-
set(CMAKE_CXX_FLAGS "/WX /wd4530")
26+
add_compile_options(/WX /wd4530)
2427
endif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
2528

29+
2630
add_subdirectory(dep)
2731

2832
add_library(inicpp INTERFACE)
@@ -32,6 +36,12 @@ target_include_directories(inicpp INTERFACE
3236
add_library(inicpp::inicpp ALIAS inicpp)
3337
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/inicpp.h TYPE INCLUDE)
3438

39+
if(GENERATE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
40+
# Add required flags (GCC & LLVM/Clang)
41+
target_compile_options(inicpp INTERFACE -O0 -g --coverage)
42+
target_link_options(inicpp INTERFACE --coverage)
43+
endif(GENERATE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
44+
3545
if(${BUILD_TESTS})
3646
add_subdirectory(test)
3747
endif(${BUILD_TESTS})

0 commit comments

Comments
 (0)