Skip to content

Commit

Permalink
feat: add test coverage (#49)
Browse files Browse the repository at this point in the history
* feat: add test coverage

* ci: install lcov

* ci: fix test coverage lcov command option
  • Loading branch information
zchrissirhcz authored Nov 1, 2021
1 parent c50e090 commit 78d13df
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ indent_size = 4

[*.{md,markdown}]
indent_size = 4

[*.yml]
indent_style = space
indent_size = 2
61 changes: 61 additions & 0 deletions .github/workflows/test-coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# GH actions

name: test-coverage

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

env:
BUILD_TYPE: Release

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Clone repository
uses: actions/checkout@v2

- name: Setup Ninja
uses: seanmiddleditch/gha-setup-ninja@v3

- name: Install googletest
shell: bash
run: |
git clone https://github.com/google/googletest --depth 1
cd googletest
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/googletest-install -G Ninja
cmake --build . --config ${{env.BUILD_TYPE}} -j 2
cmake --install . --config ${{env.BUILD_TYPE}}
- name: Install lcov
run: sudo apt-get install lcov

- name: Configure with CMake
shell: bash
run: |
mkdir build
cd build
cmake -G Ninja .. -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DSHUFACV_TEST=ON -DSHUFACV_COVERAGE=ON -DGTest_DIR=${{github.workspace}}/googletest-install/lib/cmake/GTest
- name: Building
run: cmake --build build --config ${{env.BUILD_TYPE}}
- name: Testing
working-directory: ${{github.workspace}}/build
run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure

- name: lcov-collect
run: |
cd build
lcov -d . -c -o lcov.info
lcov -r lcov.info '/usr/*' -o lcov.info
lcov -r lcov.info '*/build/*' -o lcov.info
lcov --list lcov.info
- name: codecov
uses: codecov/codecov-action@v2.1.0
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: build/lcov.info
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ __pycache__

# Build dir
build/

# VSCode
.vscode/
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ endif()
project(shufacv)

option(SHUFACV_TEST "Build unit tests?" OFF)
option(SHUFACV_COVERAGE "Build for coverage?" OFF)

if( (CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
add_compile_options(-Wextra -Wall -Wno-unused)
Expand Down Expand Up @@ -76,6 +77,11 @@ target_include_directories(
PUBLIC ${CMAKE_SOURCE_DIR}/shufaCV ${CMAKE_CURRENT_BINARY_DIR}
)

if(SHUFACV_COVERAGE)
target_compile_options(shufacv_static PUBLIC -coverage -fprofile-arcs -ftest-coverage)
target_link_libraries(shufacv_static PUBLIC -coverage -lgcov)
endif()

# Report summary
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/summary.cmake")

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

# shufaCV (书法CV)

[![License](https://img.shields.io/badge/license-BSD--3--Clause-blue.svg)](.LICENSE)
[![License](https://img.shields.io/badge/license-BSD--3--Clause-blue.svg)](.LICENSE)
[![unittest](https://github.com/scarsty/shufaCV/actions/workflows/unit_test.yml/badge.svg)](https://github.com/scarsty/shufaCV/actions/workflows/unit_test.yml)
[![codecov](https://codecov.io/gh/scarsty/shufacv/branch/main/graph/badge.svg)](https://codecov.io/gh/scarsty/shufacv)
![Widows](https://img.shields.io/badge/Windows-gray?logo=windows&logoColor=blue)
![Ubuntu](https://img.shields.io/badge/Ubuntu-gray?logo=ubuntu)
![macOS](https://img.shields.io/badge/-macOS-333333?style=flat&logo=apple)
Expand Down

0 comments on commit 78d13df

Please sign in to comment.