11# Helper so we don't have to repeat ourselves so much
2- function (add_cpp_test TEST_NAME TEST_FILE )
3- # If a source file is passed, add an executable
4- add_executable (${TEST_NAME} ${TEST_FILE} )
5- add_test (${TEST_NAME} ${TEST_NAME} )
6- if ($ARGN)
7- set_property (TEST ${TEST_NAME} APPEND PROPERTY LABELS ${ARGN} )
8- else ()
9- set_property (TEST ${TEST_NAME} APPEND PROPERTY LABELS slowtests )
2+ # Usage: add_cpp_test(testname [COMPILE_ONLY] [SOURCES a.cpp b.cpp ...] [LABELS acceptance per_implementation ...])
3+ # SOURCES defaults to testname.cpp if not specified.
4+ function (add_cpp_test TEST_NAME )
5+ # Parse arguments
6+ cmake_parse_arguments (PARSE_ARGV 1 ARGS "COMPILE_ONLY;WILL_FAIL" "" "SOURCES;LABELS" )
7+ if (NOT ARGS_SOURCES)
8+ list (APPEND ARGS_SOURCES ${TEST_NAME} .cpp)
9+ endif ()
10+ if (COMPILE_ONLY)
11+ list (APPEND ${ARGS_LABELS} compile)
1012 endif ()
11- endfunction ()
1213
13- function (add_compile_test TEST_NAME TEST_FILE )
14- add_executable (${TEST_NAME} ${TEST_FILE} )
15- set_target_properties (${TEST_NAME} PROPERTIES
16- EXCLUDE_FROM_ALL TRUE
17- EXCLUDE_FROM_DEFAULT_BUILD TRUE )
18- add_test (
19- NAME ${TEST_NAME}
20- COMMAND ${CMAKE_COMMAND} --build . --target ${TEST_NAME} --config $<CONFIGURATION >
21- WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
22- )
23- if (${ARGN} ) # Labels
24- set_property (TEST ${TEST_NAME} APPEND PROPERTY LABELS ${ARGN} )
14+ # Add executable
15+ add_executable (${TEST_NAME} ${ARGS_SOURCES} )
16+
17+ # Add test
18+ if (ARGS_COMPILE_ONLY)
19+ add_test (
20+ NAME ${TEST_NAME}
21+ COMMAND ${CMAKE_COMMAND} --build . --target ${TEST_NAME} --config $<CONFIGURATION >
22+ WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
23+ )
24+ set_target_properties (${TEST_NAME} PROPERTIES EXCLUDE_FROM_ALL TRUE EXCLUDE_FROM_DEFAULT_BUILD TRUE )
2525 else ()
26- set_property ( TEST ${TEST_NAME} APPEND PROPERTY LABELS slowtests )
26+ add_test ( ${TEST_NAME} ${TEST_NAME} )
2727 endif ()
28- endfunction (add_compile_test )
2928
29+ if (ARGS_LABELS)
30+ set_property (TEST ${TEST_NAME} APPEND PROPERTY LABELS ${ARGS_LABELS} )
31+ endif ()
32+
33+ if (ARGS_WILL_FAIL)
34+ set_property (TEST ${TEST_NAME} PROPERTY WILL_FAIL TRUE )
35+ endif ()
36+ endfunction ()
3037# Most tests need test data, and many need windows headers.
3138link_libraries (simdjson-flags test -data simdjson-windows-headers )
3239
40+ include (${PROJECT_SOURCE_DIR} /tests/add_cpp_test.cmake )
41+
3342#
3443# These tests explicitly do #include "simdjson.cpp" so they can override stuff
3544#
3645if (NOT MSVC ) # Can't get simdjson-source to compile on Windows for some reason.
37- add_cpp_test (numberparsingcheck numberparsingcheck.cpp quicktests )
46+ add_cpp_test (numberparsingcheck LABELS acceptance per_implementation )
3847 target_link_libraries (numberparsingcheck simdjson-include-source )
39- add_cpp_test (stringparsingcheck stringparsingcheck.cpp quicktests )
48+ add_cpp_test (stringparsingcheck LABELS acceptance per_implementation )
4049 target_link_libraries (stringparsingcheck simdjson-include-source )
4150endif ()
4251
4352# All remaining tests link with simdjson proper
4453link_libraries (simdjson )
45- add_cpp_test (basictests basictests.cpp quicktests )
46- add_cpp_test (errortests errortests.cpp quicktests )
47- add_cpp_test (integer_tests integer_tests.cpp quicktests )
48- add_cpp_test (jsoncheck jsoncheck.cpp quicktests )
49- add_cpp_test (parse_many_test parse_many_test.cpp quicktests )
50- add_cpp_test (pointercheck pointercheck.cpp quicktests )
51- add_cpp_test (extracting_values_example extracting_values_example.cpp quicktests )
54+ add_cpp_test (basictests LABELS acceptance per_implementation )
55+ add_cpp_test (errortests LABELS acceptance per_implementation )
56+ add_cpp_test (integer_tests LABELS acceptance per_implementation )
57+ add_cpp_test (jsoncheck LABELS acceptance per_implementation )
58+ add_cpp_test (parse_many_test LABELS acceptance per_implementation )
59+ add_cpp_test (pointercheck LABELS acceptance per_implementation )
60+ add_cpp_test (extracting_values_example LABELS acceptance per_implementation )
5261
5362# Script tests
5463if (NOT MSVC ) # Can't run .sh on windows
@@ -61,7 +70,7 @@ if (NOT MSVC) # Can't run .sh on windows
6170 WORKING_DIRECTORY $<TARGET_FILE_DIR :minify >
6271 )
6372 set_property (TEST testjson2json APPEND PROPERTY DEPENDS minify json2json )
64- set_property (TEST testjson2json APPEND PROPERTY LABELS slowtests )
73+ set_property (TEST testjson2json APPEND PROPERTY LABELS per_implementation )
6574
6675 #
6776 # Competition parse test
@@ -72,46 +81,64 @@ if (NOT MSVC) # Can't run .sh on windows
7281
7382 add_test (issue150 ${CMAKE_CURRENT_SOURCE_DIR} /issue150.sh )
7483 set_property (TEST issue150 APPEND PROPERTY DEPENDS allparserscheckfile )
75- set_property (TEST issue150 APPEND PROPERTY LABELS slowtests )
84+ set_property (TEST issue150 APPEND PROPERTY LABELS per_implementation )
7685 endif ()
7786endif ()
7887
88+ if (NOT MSVC )
89+ #
90+ # json2json tool test: check that json2json can parse twitter.json
91+ #
92+
93+ # This tests validates that the implementation is what we think it is if we get passed
94+ # SIMDJSON_FORCE_IMPLEMENTATION, so we know we're testing what we think we're testing
95+ add_cpp_test (checkimplementation LABELS per_implementation )
96+
97+ add_test (NAME json2json COMMAND $<TARGET_FILE :json2json > ${EXAMPLE_JSON} )
98+ set_property (TEST issue150 APPEND PROPERTY LABELS acceptance per_implementation )
99+
100+ #
101+ # SIMDJSON_FORCE_IMPLEMENTATION tests: run json2json with SIMDJSON
102+ #
103+ if (SIMDJSON_IMPLEMENTATION_FALLBACK)
104+ add_test (
105+ NAME simdjson_force_implementation
106+ COMMAND
107+ ${CMAKE_COMMAND} -E env
108+ SIMDJSON_FORCE_IMPLEMENTATION=fallback
109+ $<TARGET_FILE :checkimplementation >
110+ )
111+ endif ()
112+ add_test (
113+ NAME simdjson_force_implementation_error
114+ COMMAND
115+ ${CMAKE_COMMAND} -E env
116+ SIMDJSON_FORCE_IMPLEMENTATION=doesnotexist
117+ $<TARGET_FILE :json2json > ${EXAMPLE_JSON}
118+ )
119+ set_tests_properties (simdjson_force_implementation_error PROPERTIES WILL_FAIL TRUE )
120+ endif ()
121+
79122#
80123# Compile-only tests with simdjson flags on
81124#
82125
83126# Don't add the tests if we're on VS2017 or older; they don't succeed.
84127if (NOT (MSVC AND MSVC_VERSION LESS 1920))
85128 if (SIMDJSON_EXCEPTIONS)
86- add_compile_test (readme_examples readme_examples.cpp quicktests )
87- set_property (
88- TEST readme_examples
89- APPEND PROPERTY LABELS quicktests
90- )
91-
92- add_compile_test (readme_examples11 readme_examples.cpp quicktests )
129+ add_cpp_test (readme_examples COMPILE_ONLY LABELS acceptance )
130+ add_cpp_test (readme_examples11 COMPILE_ONLY LABELS acceptance SOURCES readme_examples.cpp )
93131 set_target_properties (readme_examples11 PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF )
94- if (!MSVC )
95- target_compile_options (readme_examples11 PRIVATE -Werror )
96- endif ()
97132 endif ()
98133
99- add_compile_test (readme_examples_noexceptions readme_examples_noexceptions.cpp quicktests )
134+ add_cpp_test (readme_examples_noexceptions COMPILE_ONLY LABELS acceptance )
100135
101- add_compile_test (readme_examples_noexceptions11 readme_examples_noexceptions.cpp quicktests )
136+ add_cpp_test (readme_examples_noexceptions11 COMPILE_ONLY LABELS acceptance SOURCES readme_examples_noexceptions.cpp )
102137 set_target_properties (readme_examples_noexceptions11 PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF )
103- if (!MSVC )
104- target_compile_options (readme_examples_noexceptions11 PRIVATE -Werror )
105- endif ()
106138
107139 # Compile tests that *should fail*
108- add_compile_test (readme_examples_will_fail_with_exceptions_off readme_examples.cpp quicktests )
140+ add_cpp_test (readme_examples_will_fail_with_exceptions_off WILL_FAIL COMPILE_ONLY LABELS acceptance SOURCES readme_examples.cpp )
109141 target_compile_definitions (readme_examples_will_fail_with_exceptions_off PRIVATE SIMDJSON_EXCEPTIONS=0 )
110- set_tests_properties (readme_examples_will_fail_with_exceptions_off PROPERTIES WILL_FAIL TRUE )
111- set_property (
112- TEST readme_examples_noexceptions readme_examples_will_fail_with_exceptions_off
113- APPEND PROPERTY LABELS quicktests
114- )
115142
116143endif ()
117144
0 commit comments