Skip to content

Commit

Permalink
Added code coverage testing via GitHub Actions and Codecov (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
LTLA authored Jul 21, 2021
1 parent 53d52ae commit 6ee4c9d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
33 changes: 29 additions & 4 deletions .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ jobs:
matrix:
config:
- {
name: "Ubuntu Latest GCC", artifact: "Linux.tar.xz",
os: ubuntu-latest
name: "Ubuntu Latest GCC",
os: ubuntu-latest,
cov: false
}
- {
name: "macOS Latest Clang", artifact: "macOS.tar.xz",
name: "Ubuntu Latest GCC, coverage enabled",
os: ubuntu-latest,
cov: true
}
- {
name: "macOS Latest Clang",
os: macos-latest
}

Expand All @@ -26,10 +32,29 @@ jobs:
uses: lukka/get-cmake@latest

- name: Configure the build
if: ${{ matrix.config.cov == false }}
run: cmake -S . -B build

- name: Configure the build with coverage
if: ${{ matrix.config.cov == true }}
run: cmake -S . -B build -DCODE_COVERAGE=ON

- name: Run the build
run: cmake --build build

- name: Run the tests
run: build/tests/libtest
run: |
cd build
ctest
- name: Generate code coverage
if: ${{ matrix.config.cov == true }}
run: |
cd build/tests/CMakeFiles/libtest.dir/src/
gcov -abcfu *.gcno
- name: Upload to Codecov
if: ${{ matrix.config.cov == true }}
uses: codecov/codecov-action@v1
with:
directory: build/tests/CMakeFiles/libtest.dir/src/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
![Unit tests](https://github.com/LTLA/CppKmeans/actions/workflows/run-tests.yaml/badge.svg)
![Documentation](https://github.com/LTLA/CppKmeans/actions/workflows/doxygenate.yaml/badge.svg)
![stats comparison](https://github.com/LTLA/CppKmeans/actions/workflows/compare-kmeans.yaml/badge.svg)
[![Codecov](https://codecov.io/gh/LTLA/CppKmeans/branch/master/graph/badge.svg?token=7S231XHC0Q)](https://codecov.io/gh/LTLA/CppKmeans)

## Overview

Expand Down
6 changes: 6 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ target_link_libraries(
kmeans
)

set(CODE_COVERAGE "Enable coverage testing" OFF)
if(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options(libtest PRIVATE -O0 -g --coverage)
target_link_options(libtest PRIVATE --coverage)
endif()

include(GoogleTest)
gtest_discover_tests(libtest)

Expand Down

0 comments on commit 6ee4c9d

Please sign in to comment.