Skip to content

Commit 9f1725d

Browse files
committed
Introduce coverage testing
Use LCov reports with codecov to track code coverage of the tests in debug mode. Adds a new config called "Coverage", which is used by the "ci-coverage" preset in the tracked presets file.
1 parent e1e194c commit 9f1725d

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

cmake-init/templates/common/.github/workflows/ci.yml

+35
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,41 @@ on:
1010
- master
1111

1212
jobs:
13+
coverage:
14+
runs-on: ubuntu-latest
15+
16+
# To enable coverage, go to https://codecov.io/, acquire a token, put it
17+
# into your secrets (Settings > Secrets > New repository secret) and delete
18+
# the "if" conditional below.
19+
# If you do not wish to use codecov, then simply delete this job from the
20+
# workflow.
21+
if: "false"
22+
23+
steps:
24+
- uses: actions/checkout@v1
25+
26+
- name: Install LCov
27+
run: sudo apt-get update -q
28+
&& sudo apt-get install lcov -q -y
29+
30+
- name: Configure
31+
run: cmake --preset=ci-coverage
32+
33+
- name: Build
34+
run: cmake --build build -j 2
35+
36+
- name: Test
37+
working-directory: build
38+
env:
39+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
40+
PS4: "\e[36m+++\e[0m "
41+
run: |
42+
set -x
43+
ctest --output-on-failure
44+
lcov -c -d .. -o coverage.info --include '${{ github.workspace }}/*'
45+
lcov --list coverage.info
46+
bash <(curl -s https://codecov.io/bash) -f coverage.info
47+
1348
test:
1449
strategy:
1550
matrix:

cmake-init/templates/common/CMakePresets.json

+11
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@
3434
"CMAKE_BUILD_TYPE": "Release"
3535
}
3636
},
37+
{
38+
"name": "ci-coverage",
39+
"inherits": "ci-unix",
40+
"cacheVariables": {
41+
"CMAKE_BUILD_TYPE": "Coverage",
42+
"CMAKE_CXX_FLAGS_COVERAGE": "-O0 -g --coverage",
43+
"CMAKE_EXE_LINKER_FLAGS_COVERAGE": "--coverage",
44+
"CMAKE_STATIC_LINKER_FLAGS_COVERAGE": "--coverage",
45+
"CMAKE_SHARED_LINKER_FLAGS_COVERAGE": "--coverage"
46+
}
47+
},
3748
{
3849
"name": "ci-macos",
3950
"inherits": "ci-unix"

0 commit comments

Comments
 (0)