tests: add some issue-regression-tests
This commit is contained in:
parent
a5521b4b02
commit
c552c7c02a
@ -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 $<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()
|
||||
|
||||
add_subdirectory(test)
|
||||
|
||||
13
test.sh
13
test.sh
@ -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
62
test/CMakeLists.txt
Normal 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()
|
||||
3
test/issue-12/CMakeLists.txt
Normal file
3
test/issue-12/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
||||
add_test_simple_schema(Issue::12
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/schema.json
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/instance.json)
|
||||
3
test/issue-12/instance.json
Normal file
3
test/issue-12/instance.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"x": 1503681668603
|
||||
}
|
||||
10
test/issue-12/schema.json
Normal file
10
test/issue-12/schema.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"properties": {
|
||||
"x": {
|
||||
"type": "integer",
|
||||
"minimum": 1000000000000,
|
||||
"maximum": 2000000000000
|
||||
}
|
||||
}
|
||||
}
|
||||
8
test/issue-27/CMakeLists.txt
Normal file
8
test/issue-27/CMakeLists.txt
Normal 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
1
test/issue-27/README
Normal file
@ -0,0 +1 @@
|
||||
Numbers higher that UINT32_MAX
|
||||
1
test/issue-27/instance.json
Normal file
1
test/issue-27/instance.json
Normal file
@ -0,0 +1 @@
|
||||
{"gps_time": 4294967296}
|
||||
13
test/issue-27/schema.json
Normal file
13
test/issue-27/schema.json
Normal 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
13
test/test-pipe-in.sh
Executable 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
|
||||
Loading…
Reference in New Issue
Block a user