@@ -5,23 +5,28 @@ function(add_cpp_test TEST_NAME TEST_FILE)
55endfunction (add_cpp_test )
66
77# Sets a target to only build when you run the test, and expect failure
8- function (add_compile_fail_test TEST_NAME )
8+ function (add_compile_test TEST_NAME TEST_FILE EXPECT_SUCCESS )
9+ add_executable (${TEST_NAME} ${TEST_FILE} )
910 set_target_properties (${TEST_NAME} PROPERTIES
1011 EXCLUDE_FROM_ALL TRUE
1112 EXCLUDE_FROM_DEFAULT_BUILD TRUE )
1213 add_test (NAME ${TEST_NAME}
13- COMMAND ${CMAKE_COMMAND } --build . --target ${TEST_NAME} --config $<CONFIGURATION >
14- WORKING_DIRECTORY ${CMAKE_BINARY_DIR } )
15- set_tests_properties (${TEST_NAME} PROPERTIES WILL_FAIL TRUE )
16- endfunction (add_compile_fail_test )
14+ COMMAND ${CMAKE_COMMAND } --build . --target ${TEST_NAME} --config $<CONFIGURATION >
15+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR } )
16+ if (NOT ${EXPECT_SUCCESS} )
17+ set_tests_properties (${TEST_NAME} PROPERTIES WILL_FAIL TRUE )
18+ endif ()
19+ endfunction (add_compile_test )
1720
1821#
1922# These test explicitly do #include "simdjson.cpp"
2023#
21- add_cpp_test (numberparsingcheck numberparsingcheck.cpp )
22- target_link_libraries (numberparsingcheck simdjson-source )
23- add_cpp_test (stringparsingcheck stringparsingcheck.cpp )
24- target_link_libraries (stringparsingcheck simdjson-source )
24+ if (NOT MSVC ) # Can't get simdjson-source to compile on Windows for some reason.
25+ add_cpp_test (numberparsingcheck numberparsingcheck.cpp )
26+ target_link_libraries (numberparsingcheck simdjson-source simdjson-windows-headers )
27+ add_cpp_test (stringparsingcheck stringparsingcheck.cpp )
28+ target_link_libraries (stringparsingcheck simdjson-source simdjson-windows-headers )
29+ endif ()
2530
2631#
2732# All remaining tests link with simdjson proper
@@ -33,22 +38,19 @@ add_cpp_test(basictests basictests.cpp)
3338add_cpp_test (errortests errortests.cpp )
3439add_cpp_test (integer_tests integer_tests.cpp )
3540add_cpp_test (jsoncheck jsoncheck.cpp )
41+ target_link_libraries (jsoncheck simdjson-windows-headers )
3642add_cpp_test (parse_many_test parse_many_test.cpp )
43+ target_link_libraries (parse_many_test simdjson-windows-headers )
3744add_cpp_test (pointercheck pointercheck.cpp )
3845
3946# Compile-only tests
40- add_executable (readme_examples readme_examples.cpp )
41- add_executable (readme_examples_noexceptions readme_examples_noexceptions.cpp )
42- target_compile_options (readme_examples_noexceptions PRIVATE -fno-exceptions )
43-
47+ add_compile_test (readme_examples readme_examples.cpp TRUE )
4448# Test that readme_examples does NOT compile when SIMDJSON_EXCEPTIONS=0 (i.e. test that the define
4549# works even if exceptions are on)
46- add_executable (readme_examples_will_fail_with_exceptions_off readme_examples.cpp )
50+ add_compile_test (readme_examples_will_fail_with_exceptions_off readme_examples.cpp FALSE )
4751target_compile_definitions (readme_examples_will_fail_with_exceptions_off PRIVATE SIMDJSON_EXCEPTIONS=0 )
48- add_compile_fail_test (readme_examples_will_fail_with_exceptions_off )
4952
5053if (MSVC )
51- include_directories ($<BUILD_INTERFACE :${PROJECT_SOURCE_DIR } /windows >)
5254 add_custom_command (TARGET basictests POST_BUILD # Adds a post-build event
5355 COMMAND ${CMAKE_COMMAND } -E echo "$<TARGET_FILE :simdjson >"
5456 COMMAND ${CMAKE_COMMAND } -E echo "$<TARGET_FILE_DIR :basictests >"
0 commit comments