tests: add some issue-regression-tests

This commit is contained in:
Patrick Boettcher 2018-03-30 12:26:52 +02:00
parent a5521b4b02
commit c552c7c02a
12 changed files with 115 additions and 57 deletions

View File

@ -86,47 +86,4 @@ target_link_libraries(json-schema-validate json-schema-validator)
# test-zone # test-zone
enable_testing() enable_testing()
add_subdirectory(test)
# 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 $<TARGET_FILE:json-schema-test> ${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 $<TARGET_FILE:json-schema-test> ${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()

13
test.sh
View File

@ -1,13 +0,0 @@
#!/bin/sh
if [ ! -x "$1" ]
then
exit 1
fi
if [ ! -e "$2" ]
then
exit 1
fi
$1 < $2

62
test/CMakeLists.txt Normal file
View File

@ -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}
$<TARGET_FILE:json-schema-validate>
${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} $<TARGET_FILE:json-schema-test> ${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} $<TARGET_FILE:json-schema-test> ${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()

View File

@ -0,0 +1,3 @@
add_test_simple_schema(Issue::12
${CMAKE_CURRENT_SOURCE_DIR}/schema.json
${CMAKE_CURRENT_SOURCE_DIR}/instance.json)

View File

@ -0,0 +1,3 @@
{
"x": 1503681668603
}

10
test/issue-12/schema.json Normal file
View File

@ -0,0 +1,10 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"properties": {
"x": {
"type": "integer",
"minimum": 1000000000000,
"maximum": 2000000000000
}
}
}

View File

@ -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)

1
test/issue-27/README Normal file
View File

@ -0,0 +1 @@
Numbers higher that UINT32_MAX

View File

@ -0,0 +1 @@
{"gps_time": 4294967296}

13
test/issue-27/schema.json Normal file
View File

@ -0,0 +1,13 @@
{
"properties": {
"gps_time": {
"type": "number",
"minimum": 0,
"maximum": 4294967295
}
},
"required": [
"gps_time"
],
"type": "object"
}

13
test/test-pipe-in.sh Executable file
View File

@ -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