adding coverage testing (#2)

* adding coverage testing

surprisingly:
Overall coverage rate:
  lines......: 80.6% (519 of 644 lines)
  functions..: 92.5% (235 of 254 functions)

* Update coverage.yml
This commit is contained in:
Chris Mc
2020-07-05 21:43:09 -04:00
committed by GitHub
parent e47a39fd4d
commit 22e43afba8
4 changed files with 28 additions and 1 deletions

View File

@@ -30,7 +30,7 @@ jobs:
cmake .. -DBUILD_TESTS=ON -DCOVERAGE=ON -DCMAKE_BUILD_TYPE=Debug
- name: make
run: make jwt-cpp-test coverage
run: cd build && make jwt-cpp-test coverage
- name: Coveralls GitHub Action
uses: coverallsapp/github-action@v1.1.1

View File

@@ -5,6 +5,7 @@ if(CMAKE_TOOLCHAIN_FILE)
endif()
option(BUILD_TESTS "Configure CMake to build tests (or not)" ON)
option(COVERAGE "Enable code coverage testing" OFF)
option(EXTERNAL_PICOJSON "Use find_package() to locate the picojson header" OFF)
option(DISABLE_JWT_CPP_BASE64
"Do not include the base64 implementation from this library" OFF)
@@ -16,6 +17,8 @@ project(jwt-cpp)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
find_package(OpenSSL 1.0.2 REQUIRED)
if(EXTERNAL_PICOJSON)

15
cmake/code-coverage.cmake Normal file
View File

@@ -0,0 +1,15 @@
set(COVERAGE_CMAKE "${CMAKE_BINARY_DIR}/cmake/CodeCoverage.cmake")
if(NOT EXISTS ${COVERAGE_CMAKE})
set(COVERAGE_URL
"https://raw.githubusercontent.com/bilke/cmake-modules/master/CodeCoverage.cmake"
)
file(DOWNLOAD ${COVERAGE_URL} ${COVERAGE_CMAKE})
endif()
include(${COVERAGE_CMAKE})
function(setup_coverage TARGET)
target_compile_options(${TARGET} PRIVATE -g -O0 -fprofile-arcs
-ftest-coverage)
target_link_libraries(${TARGET} PRIVATE gcov)
endfunction()

View File

@@ -35,3 +35,12 @@ target_link_libraries(jwt-cpp-test PRIVATE jwt-cpp::jwt-cpp GTest::GTest
GTest::Main pthread)
gtest_add_tests(TARGET jwt-cpp-test)
if(${COVERAGE})
include("code-coverage")
setup_coverage(jwt-cpp-test)
set(COVERAGE_EXCLUDES "/usr/**" "/home/*/.conan/**" "*test*" "*build*" "*json*")
setup_target_for_coverage_lcov(NAME coverage EXECUTABLE
${CMAKE_CURRENT_BINARY_DIR}/jwt-cpp-test)
endif()