Skip to content
This repository was archived by the owner on Apr 19, 2023. It is now read-only.

Commit ae04522

Browse files
authored
Merge pull request #191 from cpp-best-practices/fix_coverage_reporting
2 parents 1e56cae + 1bc4c99 commit ae04522

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

.github/workflows/ci.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,19 @@ jobs:
5050
compiler: gcc
5151

5252
include:
53+
# Add appropriate variables for gcov version required. This will intentionally break
54+
# if you try to use a compiler that does not have gcov set
55+
- compiler: gcc
56+
gcov_executable: gcov
57+
- compiler: llvm
58+
gcov_executable: "llvm-cov gcov"
59+
5360
# This exists solely to make sure a non-multiconfig build works
5461
- os: ubuntu-20.04
5562
compiler: gcc
5663
generator: "Unix Makefiles"
5764
build_type: Debug
65+
gcov_executable: gcov
5866
developer_mode: On
5967

6068
- os: windows-2022
@@ -119,9 +127,11 @@ jobs:
119127
gcovr: true
120128
opencppcoverage: true
121129

130+
# make sure coverage is only enabled for Debug builds, since it sets -O0 to make sure coverage
131+
# has meaningful results
122132
- name: Configure CMake
123133
run: |
124-
cmake -S . -B ./build -G "${{matrix.generator}}" -DCMAKE_BUILD_TYPE:STRING=${{matrix.build_type}} -DENABLE_DEVELOPER_MODE:BOOL=${{matrix.developer_mode}}
134+
cmake -S . -B ./build -G "${{matrix.generator}}" -DCMAKE_BUILD_TYPE:STRING=${{matrix.build_type}} -DENABLE_DEVELOPER_MODE:BOOL=${{matrix.developer_mode}} -DOPT_ENABLE_COVERAGE:BOOL=${{ matrix.build_type == 'Debug' }}
125135
126136
- name: Build
127137
# Execute the build. You can specify a specific target with "--target <NAME>"
@@ -135,13 +145,13 @@ jobs:
135145
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
136146
run: |
137147
ctest -C ${{matrix.build_type}}
138-
gcovr -j ${{env.nproc}} --delete --root ../ --print-summary --xml-pretty --xml coverage.xml .
148+
gcovr -j ${{env.nproc}} --delete --root ../ --print-summary --xml-pretty --xml coverage.xml . --gcov-executable '${{ matrix.gcov_executable }}'
139149
140150
- name: Windows - Test and coverage
141151
if: runner.os == 'Windows'
142152
working-directory: ./build
143153
run: |
144-
OpenCppCoverage.exe --sources cpp_starter_project --export_type cobertura:coverage.xml --cover_children -- ctest -C ${{matrix.build_type}}
154+
OpenCppCoverage.exe --export_type cobertura:coverage.xml --cover_children -- ctest -C ${{matrix.build_type}}
145155
146156
- name: Publish to codecov
147157
uses: codecov/codecov-action@v2

.lgtm.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ extraction:
1919
configure:
2020
command:
2121
- mkdir build
22-
- cmake -D ENABLE_COVERAGE:BOOL=TRUE -S . -B build
22+
- cmake -D OPT_ENABLE_COVERAGE:BOOL=TRUE -D CMAKE_BUILD_TYPE:STRING=Debug -D ENABLE_DEVELOPER_MODE:BOOL=FALSE -S . -B build
2323
index:
2424
build_command: cmake --build ./build -- -j2

test/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ add_library(catch_main OBJECT catch_main.cpp)
77
target_link_libraries(catch_main PUBLIC Catch2::Catch2)
88
target_link_libraries(catch_main PRIVATE project_options)
99

10+
# Provide a simple smoke test to make sure that the CLI works and can display a --help message
11+
add_test(NAME cli.has_help COMMAND intro --help)
12+
1013
add_executable(tests tests.cpp)
1114
target_link_libraries(tests PRIVATE project_warnings project_options catch_main)
1215

0 commit comments

Comments
 (0)