Skip to content

Commit 4649f72

Browse files
committed
Add code coverage to readme
1 parent 2bc0c4f commit 4649f72

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

.github/workflows/test.yml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ on:
99
jobs:
1010
test:
1111
runs-on: ubuntu-latest
12+
permissions:
13+
pull-requests: write
1214
steps:
1315
- uses: actions/checkout@v6
1416
with:
@@ -17,11 +19,11 @@ jobs:
1719
- name: Install build dependencies from debian/control
1820
run: |
1921
sudo apt-get update
20-
sudo apt-get install --yes devscripts equivs ninja-build
22+
sudo apt-get install --yes devscripts equivs ninja-build lcov
2123
sudo mk-build-deps -i -r -t "apt-get --yes" debian/control
2224
2325
- name: Configure
24-
run: cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug -DUSE_STATIC_MPVQT=ON
26+
run: cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug -DUSE_STATIC_MPVQT=ON -DCOVERAGE=ON
2527

2628
- name: Build
2729
run: cmake --build build
@@ -30,3 +32,27 @@ jobs:
3032
run: |
3133
cd build
3234
ctest --output-on-failure
35+
36+
- name: Collect coverage
37+
run: |
38+
lcov --capture --directory build --output-file coverage.info \
39+
--ignore-errors mismatch
40+
lcov --remove coverage.info \
41+
'/usr/*' '*/external/*' '*/tests/*' '*/build/*' \
42+
--output-file coverage.info \
43+
--ignore-errors unused
44+
lcov --summary coverage.info > coverage_summary.txt 2>&1
45+
46+
- name: Comment coverage on PR
47+
if: github.event_name == 'pull_request'
48+
env:
49+
GH_TOKEN: ${{ github.token }}
50+
run: |
51+
{
52+
echo "## Test Coverage"
53+
echo ""
54+
echo '```'
55+
cat coverage_summary.txt
56+
echo '```'
57+
} > comment_body.md
58+
gh pr comment "${{ github.event.pull_request.number }}" --body-file comment_body.md

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ option(OPENELEC "Make an OpenELEC build" OFF)
1515
option(LINUX_X11POWER "Enable non D-Bus screensaver management" OFF)
1616
option(USE_STATIC_MPVQT "Build MpvQt from bundled submodule instead of using system library" OFF)
1717
option(MACOS_LAUNCH_WRAPPER "Wrap macOS binary in a shell script to block DYLD_FRAMEWORK_PATH injection" OFF)
18+
option(COVERAGE "Gemerate test code coverage with gcov" OFF)
1819

1920
if (NOT CHECK_FOR_UPDATES)
2021
add_definitions(-DDISABLE_UPDATE_CHECK)
@@ -35,6 +36,11 @@ if(BUILD_TARGET STREQUAL "RPI")
3536
Message(STATUS "Build for Raspberry PI target")
3637
endif(BUILD_TARGET STREQUAL "RPI")
3738

39+
if(COVERAGE)
40+
add_compile_options(--coverage -fno-inline)
41+
add_link_options(--coverage)
42+
endif()
43+
3844
set(CMAKE_INCLUDE_CURRENT_DIR ON)
3945
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/")
4046
set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME Core)

0 commit comments

Comments
 (0)