diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index da22d3f..6ccea02 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -41,8 +41,7 @@ jobs: needs: [ test ] runs-on: ubuntu-latest container: ghcr.io/nlohmann/json-ci:v2.4.0 - # TODO: Temporarily disabled because not implemented - if: ${{ false && (github.event_name == 'push' || github.event_name == 'pull_request') }} + if: ${{ github.event_name == 'push' || github.event_name == 'pull_request' }} steps: - uses: actions/checkout@v3 - name: Get test coverage diff --git a/CMakeLists.txt b/CMakeLists.txt index a02f929..cfce8e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,8 @@ option(JSON_VALIDATOR_INSTALL "JsonValidator: Install targets" ${PROJECT_IS_TOP_ option(JSON_VALIDATOR_BUILD_TESTS "JsonValidator: Build tests" ${PROJECT_IS_TOP_LEVEL}) option(JSON_VALIDATOR_BUILD_EXAMPLES "JsonValidator: Build examples" ${PROJECT_IS_TOP_LEVEL}) option(JSON_VALIDATOR_SHARED_LIBS "JsonValidator: Build as shared library" ${PROJECT_IS_TOP_LEVEL}) +option(JSON_VALIDATOR_TEST_COVERAGE "JsonValidator: Build with test coverage" OFF) +mark_as_advanced(JSON_VALIDATOR_TEST_COVERAGE) # Get a default JSON_FETCH_VERSION from environment variables to workaround the CI if (DEFINED ENV{NLOHMANN_JSON_VERSION}) set(JSON_FETCH_VERSION_DEFAULT $ENV{NLOHMANN_JSON_VERSION}) @@ -60,6 +62,19 @@ endif () # Enable cmake's BUILD_SHARED_LIBS set(BUILD_SHARED_LIBS ${nlohmann_json_schema_validator_SHARED_LIBS}) +if (JSON_VALIDATOR_TEST_COVERAGE) + if (CMAKE_CXX_COMPILER_ID STREQUAL Clang) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-instr-generate -fcoverage-mapping") + elseif (CMAKE_CXX_COMPILER_ID STREQUAL GNU) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage") + else () + message(WARNING + "JsonValidator: Other toolchain coverage flags unknown.\n" + "Using --coverage as default") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage") + endif () +endif () + #[==============================================================================================[ # External packages # ]==============================================================================================] diff --git a/cmake/CMakePresets-CI.json b/cmake/CMakePresets-CI.json index 4dae53c..5686db5 100644 --- a/cmake/CMakePresets-CI.json +++ b/cmake/CMakePresets-CI.json @@ -80,6 +80,12 @@ "binaryDir": "cmake-build-coverage", "errors": { "deprecated": false + }, + "cacheVariables": { + "JSON_VALIDATOR_TEST_COVERAGE": { + "type": "BOOL", + "value": true + } } }, {