From 4fb5feb21fbb59d26f2ca58d5958105054b42f13 Mon Sep 17 00:00:00 2001 From: Chris Mc Date: Sun, 5 Jul 2020 20:48:44 -0400 Subject: [PATCH 1/2] adding coverage testing surprisingly: Overall coverage rate: lines......: 80.6% (519 of 644 lines) functions..: 92.5% (235 of 254 functions) --- CMakeLists.txt | 3 +++ cmake/code-coverage.cmake | 15 +++++++++++++++ tests/CMakeLists.txt | 9 +++++++++ 3 files changed, 27 insertions(+) create mode 100644 cmake/code-coverage.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 0e7e45931..136056db3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/cmake/code-coverage.cmake b/cmake/code-coverage.cmake new file mode 100644 index 000000000..fd7da29ca --- /dev/null +++ b/cmake/code-coverage.cmake @@ -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() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c0060b9d8..22e3b6f1f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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() From ba7407f89c9b618e3cebaeb598f380911a1c7232 Mon Sep 17 00:00:00 2001 From: Chris Mc Date: Sun, 5 Jul 2020 21:39:56 -0400 Subject: [PATCH 2/2] Update coverage.yml --- .github/workflows/coverage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index edcbb3bb5..0f3f30b3a 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -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