diff --git a/CMakeLists.txt b/CMakeLists.txt index 2da3c4f..ec9f365 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,47 +86,4 @@ target_link_libraries(json-schema-validate json-schema-validator) # test-zone enable_testing() - -# find schema-test-suite -find_path(JSON_SCHEMA_TEST_SUITE_PATH - NAMES - tests/draft4) - -set(JSON_SCHEMA_TEST_PREFIX "JSON-Suite" CACHE STRING "prefix for JSON-tests added to ctest") - -if(JSON_SCHEMA_TEST_SUITE_PATH) - # json-schema-validator-tester - add_executable(json-schema-test app/json-schema-test.cpp) - target_link_libraries(json-schema-test json-schema-validator) - target_compile_definitions(json-schema-test - PRIVATE - JSON_SCHEMA_TEST_SUITE_PATH="${JSON_SCHEMA_TEST_SUITE_PATH}") - - option(JSON_SCHEMA_ENABLE_OPTIONAL_TESTS "Enable optional tests of the JSONSchema Test Suite" ON) - - # create tests foreach test-file - file(GLOB TEST_FILES ${JSON_SCHEMA_TEST_SUITE_PATH}/tests/draft4/*.json) - - foreach(TEST_FILE ${TEST_FILES}) - get_filename_component(TEST_NAME ${TEST_FILE} NAME_WE) - add_test( - NAME "${JSON_SCHEMA_TEST_PREFIX}::${TEST_NAME}" - COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test.sh $ ${TEST_FILE} - ) - endforeach() - - if (JSON_SCHEMA_ENABLE_OPTIONAL_TESTS) - file(GLOB OPT_TEST_FILES ${JSON_SCHEMA_TEST_SUITE_PATH}/tests/draft4/optional/*.json) - - foreach(TEST_FILE ${OPT_TEST_FILES}) - get_filename_component(TEST_NAME ${TEST_FILE} NAME_WE) - add_test( - NAME "${JSON_SCHEMA_TEST_PREFIX}::Optional::${TEST_NAME}" - COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test.sh $ ${TEST_FILE} - ) - endforeach() - endif() -else() - message(STATUS "Consider setting JSON_SCHEMA_TEST_SUITE_PATH to a path in which JSON-Schema-Test-Suite is located (github.com/json-schema-org/JSON-Schema-Test-Suite).") -endif() - +add_subdirectory(test) diff --git a/test.sh b/test.sh deleted file mode 100755 index acd5157..0000000 --- a/test.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh - -if [ ! -x "$1" ] -then - exit 1 -fi - -if [ ! -e "$2" ] -then - exit 1 -fi - -$1 < $2 diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..6ec2e18 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,62 @@ +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} + $ + ${schema} + ${instance}) +endfunction() + +file(GLOB TEST_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/*) + +foreach(DIR ${TEST_DIRS}) + if(IS_DIRECTORY ${DIR}) + add_subdirectory(${DIR}) + endif() +endforeach() + +# find schema-test-suite +find_path(JSON_SCHEMA_TEST_SUITE_PATH + NAMES + tests/draft4) + +set(JSON_SCHEMA_TEST_PREFIX "JSON-Suite" CACHE STRING "prefix for JSON-tests added to ctest") + +if(JSON_SCHEMA_TEST_SUITE_PATH) + # json-schema-validator-tester + add_executable(json-schema-test ${CMAKE_SOURCE_DIR}/app/json-schema-test.cpp) + target_link_libraries(json-schema-test json-schema-validator) + target_compile_definitions(json-schema-test + PRIVATE + JSON_SCHEMA_TEST_SUITE_PATH="${JSON_SCHEMA_TEST_SUITE_PATH}") + + option(JSON_SCHEMA_ENABLE_OPTIONAL_TESTS "Enable optional tests of the JSONSchema Test Suite" ON) + + # create tests foreach test-file + file(GLOB TEST_FILES ${JSON_SCHEMA_TEST_SUITE_PATH}/tests/draft4/*.json) + + foreach(TEST_FILE ${TEST_FILES}) + get_filename_component(TEST_NAME ${TEST_FILE} NAME_WE) + add_test( + NAME "${JSON_SCHEMA_TEST_PREFIX}::${TEST_NAME}" + COMMAND ${PIPE_IN_TEST_SCRIPT} $ ${TEST_FILE} + ) + endforeach() + + if (JSON_SCHEMA_ENABLE_OPTIONAL_TESTS) + file(GLOB OPT_TEST_FILES ${JSON_SCHEMA_TEST_SUITE_PATH}/tests/draft4/optional/*.json) + + foreach(TEST_FILE ${OPT_TEST_FILES}) + get_filename_component(TEST_NAME ${TEST_FILE} NAME_WE) + add_test( + NAME "${JSON_SCHEMA_TEST_PREFIX}::Optional::${TEST_NAME}" + COMMAND ${PIPE_IN_TEST_SCRIPT} $ ${TEST_FILE} + ) + endforeach() + endif() +else() + message(STATUS "Consider setting JSON_SCHEMA_TEST_SUITE_PATH to a path in which JSON-Schema-Test-Suite is located (github.com/json-schema-org/JSON-Schema-Test-Suite).") +endif() diff --git a/test/issue-12/CMakeLists.txt b/test/issue-12/CMakeLists.txt new file mode 100644 index 0000000..5dc7595 --- /dev/null +++ b/test/issue-12/CMakeLists.txt @@ -0,0 +1,3 @@ +add_test_simple_schema(Issue::12 + ${CMAKE_CURRENT_SOURCE_DIR}/schema.json + ${CMAKE_CURRENT_SOURCE_DIR}/instance.json) diff --git a/test/issue-12/instance.json b/test/issue-12/instance.json new file mode 100644 index 0000000..13b78c1 --- /dev/null +++ b/test/issue-12/instance.json @@ -0,0 +1,3 @@ +{ + "x": 1503681668603 +} diff --git a/test/issue-12/schema.json b/test/issue-12/schema.json new file mode 100644 index 0000000..ab104fa --- /dev/null +++ b/test/issue-12/schema.json @@ -0,0 +1,10 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "properties": { + "x": { + "type": "integer", + "minimum": 1000000000000, + "maximum": 2000000000000 + } + } +} diff --git a/test/issue-27/CMakeLists.txt b/test/issue-27/CMakeLists.txt new file mode 100644 index 0000000..949479e --- /dev/null +++ b/test/issue-27/CMakeLists.txt @@ -0,0 +1,8 @@ +add_test_simple_schema(Issue::27 + ${CMAKE_CURRENT_SOURCE_DIR}/schema.json + ${CMAKE_CURRENT_SOURCE_DIR}/instance.json) +set_tests_properties(Issue::27 + PROPERTIES + WILL_FAIL 1) + + diff --git a/test/issue-27/README b/test/issue-27/README new file mode 100644 index 0000000..ac34a62 --- /dev/null +++ b/test/issue-27/README @@ -0,0 +1 @@ +Numbers higher that UINT32_MAX diff --git a/test/issue-27/instance.json b/test/issue-27/instance.json new file mode 100644 index 0000000..b89e11e --- /dev/null +++ b/test/issue-27/instance.json @@ -0,0 +1 @@ +{"gps_time": 4294967296} diff --git a/test/issue-27/schema.json b/test/issue-27/schema.json new file mode 100644 index 0000000..670fb6c --- /dev/null +++ b/test/issue-27/schema.json @@ -0,0 +1,13 @@ +{ + "properties": { + "gps_time": { + "type": "number", + "minimum": 0, + "maximum": 4294967295 + } + }, + "required": [ + "gps_time" + ], + "type": "object" +} diff --git a/test/test-pipe-in.sh b/test/test-pipe-in.sh new file mode 100755 index 0000000..ac57a77 --- /dev/null +++ b/test/test-pipe-in.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# all argument are considered as a program to call (with its arguments), +# the last argument is read from via '<' + +set -e + +arr=( "$@" ) + +input=${arr[-1]} +unset 'arr[${#arr[@]}-1]' + +${arr[@]} < $input diff --git a/test-schema.sh b/test/test-schema.sh similarity index 100% rename from test-schema.sh rename to test/test-schema.sh