From 13f6b1697769537acbc7d2e5d8897d74f1e13ce7 Mon Sep 17 00:00:00 2001 From: Marcus Tomlinson Date: Tue, 9 Jan 2024 13:52:23 +0000 Subject: [PATCH] Add test coverage to CI --- .github/workflows/build_and_test.yml | 17 +++++++++++++++-- meson.build | 20 ++++++++++++++++++++ tests/meson.build | 14 +++++++++++++- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 383a76a..0027b11 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -15,10 +15,12 @@ jobs: steps: - if: matrix.os == 'windows-2022' - name: Install Cppcheck (Windows) + name: Install Cppcheck, OpenCppCoverage, and wkhtmltopdf (Windows) run: | - choco install -y --ignore-package-exit-codes cppcheck + choco install -y --ignore-package-exit-codes cppcheck opencppcoverage wkhtmltopdf echo "C:\Program Files\Cppcheck" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + echo "C:\Program Files\OpenCppCoverage" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + echo "C:\Program Files\wkhtmltopdf" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - if: matrix.os == 'windows-2022' name: Configure MSVC (Windows) @@ -57,3 +59,14 @@ jobs: name: Test - Debug (Windows) run: | meson test -vC builddir + meson compile ./codecoverage -C builddir + $files = (Get-ChildItem -R .\builddir\coverage\*.html) + [array]::Reverse($files) + wkhtmltopdf --enable-local-file-access --disable-external-links --header-center [title] $files coverage.pdf + + - if: matrix.os == 'windows-2022' + name: Upload Coverage Report (Windows) + uses: actions/upload-artifact@v3 + with: + name: coverage + path: coverage.pdf diff --git a/meson.build b/meson.build index b89f061..0a88312 100644 --- a/meson.build +++ b/meson.build @@ -13,6 +13,26 @@ else add_project_arguments(['-D_CRT_SECURE_NO_WARNINGS'], language: 'cpp') endif +# Add code coverage + +opencppcoverage = find_program('opencppcoverage', required: false) + +opencppcoverage_args = [ + '--sources', meson.project_name(), + '--excluded_sources', 'subprojects', + '--excluded_sources', 'tests' +] + +if opencppcoverage.found() + run_target('codecoverage', + command: [ + opencppcoverage, + '--input_coverage', 'IpcTests.cov', + '--export_type', 'html:coverage' + ] + ) +endif + # Add formatting format_first = [] diff --git a/tests/meson.build b/tests/meson.build index afb40b7..ee5758e 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -17,4 +17,16 @@ ipc_tests = executable( dependencies: [gtest_dep, gmock_dep, ipc_dep] ) -test('IpcTests', ipc_tests) +# Add code coverage + +if opencppcoverage.found() + test('IpcTests', opencppcoverage, + args: [ + opencppcoverage_args, + '--export_type', 'binary:IpcTests.cov', + ipc_tests + ] + ) +else + test('IpcTests', ipc_tests) +endif