193 lines
8.3 KiB
CMake
193 lines
8.3 KiB
CMake
cmake_minimum_required(VERSION 3.14)
|
|
|
|
#[==============================================================================================[
|
|
# Basic project definition #
|
|
]==============================================================================================]
|
|
|
|
list(APPEND CMAKE_MESSAGE_CONTEXT Test)
|
|
project(nlohmann_json_schema_validator_test
|
|
LANGUAGES CXX
|
|
)
|
|
|
|
#[==============================================================================================[
|
|
# Options #
|
|
]==============================================================================================]
|
|
|
|
include(CMakeDependentOption)
|
|
cmake_dependent_option(JSON_VALIDATOR_TEST_COVERAGE "JsonValidator: Build with test coverage" OFF "nlohmann_json_schema_validator_IS_TOP_LEVEL" OFF)
|
|
mark_as_advanced(JSON_VALIDATOR_TEST_COVERAGE)
|
|
|
|
#[==============================================================================================[
|
|
# Project configuration #
|
|
]==============================================================================================]
|
|
|
|
include(FetchContent)
|
|
|
|
if (JSON_VALIDATOR_TEST_COVERAGE)
|
|
if (NOT CMAKE_CXX_COMPILER_ID MATCHES "(Clang|GNU)")
|
|
message(WARNING
|
|
"Coverage flags not known for: ${CMAKE_CXX_COMPILER_ID}.\n"
|
|
"Using --coverage as default")
|
|
endif ()
|
|
target_compile_options(nlohmann_json_schema_validator PRIVATE --coverage)
|
|
target_link_options(nlohmann_json_schema_validator PUBLIC --coverage)
|
|
endif ()
|
|
|
|
#[==============================================================================================[
|
|
# External packages #
|
|
]==============================================================================================]
|
|
|
|
set(fetch_packages)
|
|
if (NOT TARGET nlohmann_json_schema_validator::validator)
|
|
# Fetch/Find nlohmann_json_schema_validator
|
|
# TODO: Remove when bumping cmake >= 3.24
|
|
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.24)
|
|
FetchContent_Declare(nlohmann_json_schema_validator
|
|
GIT_REPOSITORY https://github.com/pboettch/json-schema-validator
|
|
GIT_TAG main
|
|
FIND_PACKAGE_ARGS CONFIG
|
|
)
|
|
list(APPEND fetch_packages nlohmann_json_schema_validator)
|
|
else ()
|
|
# Try to get system installed version
|
|
find_package(nlohmann_json_schema_validator QUIET)
|
|
if (NOT nlohmann_json_schema_validator_FOUND)
|
|
# If failed fetch the desired version
|
|
FetchContent_Declare(nlohmann_json_schema_validator
|
|
GIT_REPOSITORY https://github.com/pboettch/json-schema-validator
|
|
GIT_TAG main
|
|
)
|
|
list(APPEND fetch_packages nlohmann_json_schema_validator)
|
|
endif ()
|
|
endif ()
|
|
endif ()
|
|
# Fetch/Find Catch2
|
|
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.24)
|
|
FetchContent_Declare(Catch2
|
|
GIT_REPOSITORY https://github.com/catchorg/Catch2
|
|
GIT_TAG v3.4.0
|
|
FIND_PACKAGE_ARGS CONFIG
|
|
)
|
|
list(APPEND fetch_packages Catch2)
|
|
else ()
|
|
# Try to get system installed version
|
|
find_package(Catch2 QUIET)
|
|
if (NOT Catch2_FOUND)
|
|
# If failed fetch the desired version
|
|
FetchContent_Declare(Catch2
|
|
GIT_REPOSITORY https://github.com/catchorg/Catch2
|
|
GIT_TAG v3.4.0
|
|
)
|
|
list(APPEND fetch_packages Catch2)
|
|
endif ()
|
|
endif ()
|
|
|
|
# Get all dependencies
|
|
FetchContent_MakeAvailable(${fetch_packages})
|
|
|
|
#[==============================================================================================[
|
|
# Main definition #
|
|
]==============================================================================================]
|
|
|
|
enable_testing()
|
|
include(Catch)
|
|
|
|
add_executable(json-schema-test-suite)
|
|
set_target_properties(json-schema-test-suite PROPERTIES
|
|
OUTPUT_NAME test-suite
|
|
)
|
|
target_link_libraries(json-schema-test-suite PRIVATE Catch2::Catch2WithMain nlohmann_json_schema_validator::validator)
|
|
catch_discover_tests(json-schema-test-suite)
|
|
|
|
set(PIPE_IN_TEST_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/test-pipe-in.sh)
|
|
|
|
# built-in tests
|
|
function(add_test_simple_schema name schema instance)
|
|
add_test(
|
|
NAME ${name}
|
|
COMMAND ${PIPE_IN_TEST_SCRIPT}
|
|
$<TARGET_FILE:json-schema-validate>
|
|
${schema}
|
|
${instance}
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
|
|
endfunction()
|
|
|
|
file(GLOB TEST_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/*)
|
|
|
|
foreach(DIR ${TEST_DIRS})
|
|
if(IS_DIRECTORY ${DIR})
|
|
add_subdirectory(${DIR})
|
|
endif()
|
|
endforeach()
|
|
|
|
add_executable(uri uri.cpp)
|
|
target_link_libraries(uri nlohmann_json_schema_validator)
|
|
add_test(NAME uri COMMAND uri)
|
|
|
|
add_executable(errors errors.cpp)
|
|
target_link_libraries(errors nlohmann_json_schema_validator)
|
|
add_test(NAME errors COMMAND errors)
|
|
|
|
add_executable(issue-70 issue-70.cpp)
|
|
target_link_libraries(issue-70 nlohmann_json_schema_validator)
|
|
add_test(NAME issue-70 COMMAND issue-70)
|
|
|
|
add_executable(issue-70-root-schema-constructor issue-70-root-schema-constructor.cpp)
|
|
target_link_libraries(issue-70-root-schema-constructor nlohmann_json_schema_validator)
|
|
add_test(NAME issue-70-root-schema-constructor COMMAND issue-70-root-schema-constructor)
|
|
|
|
add_executable(issue-25-default-values issue-25-default-values.cpp)
|
|
target_link_libraries(issue-25-default-values nlohmann_json_schema_validator)
|
|
add_test(NAME issue-25-default-values COMMAND issue-25-default-values)
|
|
|
|
add_executable(issue-98 issue-98.cpp)
|
|
target_link_libraries(issue-98 nlohmann_json_schema_validator)
|
|
add_test(NAME issue-98-erase-exception-unknown-keywords COMMAND issue-98)
|
|
|
|
add_executable(issue-293 issue-293.cpp)
|
|
target_link_libraries(issue-293 nlohmann_json_schema_validator)
|
|
add_test(NAME issue-293-float-point-error COMMAND issue-293)
|
|
|
|
# Unit test for string format checks
|
|
add_executable(string-format-check-test string-format-check-test.cpp)
|
|
target_include_directories(string-format-check-test PRIVATE ${PROJECT_SOURCE_DIR}/src/)
|
|
target_link_libraries(string-format-check-test nlohmann_json_schema_validator)
|
|
|
|
add_test(NAME string-format-check-test COMMAND string-format-check-test)
|
|
|
|
# Unit test for json-patch
|
|
add_executable(json-patch json-patch.cpp)
|
|
target_include_directories(json-patch PRIVATE ${PROJECT_SOURCE_DIR}/src)
|
|
target_link_libraries(json-patch nlohmann_json_schema_validator)
|
|
add_test(NAME json-patch COMMAND json-patch)
|
|
|
|
# Unit test for format checker fail at schema parsing time
|
|
add_executable(issue-117-format-error issue-117-format-error.cpp)
|
|
target_link_libraries(issue-117-format-error nlohmann_json_schema_validator)
|
|
add_test(NAME issue-117-format-error COMMAND issue-117-format-error)
|
|
|
|
add_executable(binary-validation binary-validation.cpp)
|
|
target_include_directories(binary-validation PRIVATE ${PROJECT_SOURCE_DIR}/src)
|
|
target_link_libraries(binary-validation PRIVATE nlohmann_json_schema_validator)
|
|
add_test(NAME binary-validation COMMAND binary-validation)
|
|
|
|
add_executable(issue-149-entry-selection issue-149-entry-selection.cpp)
|
|
target_link_libraries(issue-149-entry-selection PRIVATE nlohmann_json_schema_validator)
|
|
add_test(NAME issue-149-entry-selection COMMAND issue-149-entry-selection)
|
|
|
|
add_executable(issue-189-default-values issue-189-default-values.cpp)
|
|
target_link_libraries(issue-189-default-values nlohmann_json_schema_validator)
|
|
add_test(NAME issue-189-default-values COMMAND issue-189-default-values)
|
|
|
|
add_executable(issue-229-oneof-default-values issue-229-oneof-default-values.cpp)
|
|
target_link_libraries(issue-229-oneof-default-values nlohmann_json_schema_validator)
|
|
add_test(NAME issue-229-oneof-default-values COMMAND issue-229-oneof-default-values)
|
|
|
|
add_executable(issue-243-root-default-values issue-243-root-default-values.cpp)
|
|
target_link_libraries(issue-243-root-default-values nlohmann_json_schema_validator)
|
|
add_test(NAME issue-243-root-default-values COMMAND issue-243-root-default-values)
|
|
|
|
add_executable(issue-255-error-message-limit-precision issue-255-error-message-limit-precision.cpp)
|
|
target_link_libraries(issue-255-error-message-limit-precision nlohmann_json_schema_validator)
|
|
add_test(NAME issue-255-error-message-limit-precision COMMAND issue-255-error-message-limit-precision)
|