From ceb1def55c031a3312983179905a9425b2541aca Mon Sep 17 00:00:00 2001 From: John Keiser Date: Thu, 9 Apr 2020 09:08:36 -0700 Subject: [PATCH] Add quicktests, slowtests to cmake - Also add testjson2json.sh - Move test scripts to tests directory to consolidate concerns --- Makefile | 4 +- scripts/CMakeLists.txt | 7 --- tests/CMakeLists.txt | 67 +++++++++++++++++++---------- {scripts => tests}/issue150.sh | 0 {scripts => tests}/testjson2json.sh | 47 ++++---------------- 5 files changed, 56 insertions(+), 69 deletions(-) delete mode 100644 scripts/CMakeLists.txt rename {scripts => tests}/issue150.sh (100%) rename {scripts => tests}/testjson2json.sh (54%) diff --git a/Makefile b/Makefile index 06d80a75..bddcf540 100644 --- a/Makefile +++ b/Makefile @@ -139,7 +139,7 @@ run_pointercheck: pointercheck ./pointercheck run_issue150_sh: allparserscheckfile - ./scripts/issue150.sh + ./tests/issue150.sh quickstart: amalgamate cd examples/quickstart && make quickstart @@ -160,7 +160,7 @@ run_quickstart14: amalgamate cd examples/quickstart && make test14 run_testjson2json_sh: minify json2json - ./scripts/testjson2json.sh + ./tests/testjson2json.sh $(FEATURE_JSON_FILES): benchmark/genfeaturejson.rb ruby ./benchmark/genfeaturejson.rb diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt deleted file mode 100644 index 2e5d6527..00000000 --- a/scripts/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -if (SIMDJSON_COMPETITION) - add_test( - NAME issue150 - COMMAND ${PROJECT_SOURCE_DIR}/scripts/issue150.sh - WORKING_DIRECTORY $ - ) -endif() \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 195b011d..138691f6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -2,32 +2,46 @@ function(add_cpp_test TEST_NAME TEST_FILE) add_executable(${TEST_NAME} ${TEST_FILE}) add_test(${TEST_NAME} ${TEST_NAME}) - target_link_libraries(${TEST_NAME} test-data) endfunction(add_cpp_test) -# -# These test explicitly do #include "simdjson.cpp" -# -if (NOT MSVC) # Can't get simdjson-source to compile on Windows for some reason. - add_cpp_test(numberparsingcheck numberparsingcheck.cpp) - target_link_libraries(numberparsingcheck simdjson-source test-data simdjson-windows-headers) - add_cpp_test(stringparsingcheck stringparsingcheck.cpp) - target_link_libraries(stringparsingcheck simdjson-source test-data simdjson-windows-headers) -endif() +# Most tests need test data, and many need windows headers. +link_libraries(test-data simdjson-windows-headers) # -# All remaining tests link with simdjson proper +# These test explicitly do #include "simdjson.cpp" so they can override stuff # +if (NOT MSVC) # Can't get simdjson-source to compile on Windows for some reason. + add_cpp_test(numberparsingcheck numberparsingcheck.cpp quicktests) + target_link_libraries(numberparsingcheck simdjson-source) + add_cpp_test(stringparsingcheck stringparsingcheck.cpp quicktests) + target_link_libraries(stringparsingcheck simdjson-source) +endif() + +# All remaining tests link with simdjson proper link_libraries(simdjson) add_cpp_test(basictests basictests.cpp) add_cpp_test(errortests errortests.cpp) add_cpp_test(integer_tests integer_tests.cpp) add_cpp_test(jsoncheck jsoncheck.cpp) -target_link_libraries(jsoncheck simdjson-windows-headers) add_cpp_test(parse_many_test parse_many_test.cpp) -target_link_libraries(parse_many_test simdjson-windows-headers) -add_cpp_test(pointercheck pointercheck.cpp) +add_cpp_test(pointercheck pointercheck.cpp quicktests) + +set_property( + TEST basictests errortests integer_tests jsoncheck parse_many_test pointercheck + APPEND PROPERTY LABELS quicktests +) + +# +# json2json test +# +add_test( + NAME testjson2json + COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/testjson2json.sh + WORKING_DIRECTORY $ +) +set_property(TEST testjson2json APPEND PROPERTY DEPENDS minify json2json) +set_property(TEST testjson2json APPEND PROPERTY LABELS slowtests) # # Competition parse test @@ -35,12 +49,16 @@ add_cpp_test(pointercheck pointercheck.cpp) if (SIMDJSON_COMPETITION) add_executable(allparserscheckfile allparserscheckfile.cpp) target_link_libraries(allparserscheckfile competition-all) + + add_test(issue150 issue150.sh) + set_property(TEST issue150 APPEND PROPERTY DEPENDS allparserscheckfile) + set_property(TEST issue150 APPEND PROPERTY LABELS slowtests) endif() # # Compile-only tests # -function(add_compile_test TEST_NAME TEST_FILE EXPECT_SUCCESS) +function(add_compile_test TEST_NAME TEST_FILE) add_executable(${TEST_NAME} ${TEST_FILE}) set_target_properties(${TEST_NAME} PROPERTIES EXCLUDE_FROM_ALL TRUE @@ -48,20 +66,25 @@ function(add_compile_test TEST_NAME TEST_FILE EXPECT_SUCCESS) add_test(NAME ${TEST_NAME} COMMAND ${CMAKE_COMMAND} --build . --target ${TEST_NAME} --config $ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) - if(NOT ${EXPECT_SUCCESS}) - set_tests_properties(${TEST_NAME} PROPERTIES WILL_FAIL TRUE) - endif() endfunction(add_compile_test) # Don't add the tests if we're on VS2017 or older; they don't succeed. if(NOT (MSVC AND MSVC_VERSION LESS 1920)) - add_compile_test(readme_examples readme_examples.cpp TRUE) - # Test that readme_examples does NOT compile when SIMDJSON_EXCEPTIONS=0 (i.e. test that the define - # works even if exceptions are on) - add_compile_test(readme_examples_will_fail_with_exceptions_off readme_examples.cpp FALSE) + add_compile_test(readme_examples readme_examples.cpp quicktests) + add_compile_test(readme_examples_noexceptions readme_examples_noexceptions.cpp quicktests) + + # Compile tests that *should fail* + add_compile_test(readme_examples_will_fail_with_exceptions_off readme_examples.cpp FALSE quicktests) target_compile_definitions(readme_examples_will_fail_with_exceptions_off PRIVATE SIMDJSON_EXCEPTIONS=0) + set_tests_properties(readme_examples_will_fail_with_exceptions_off PROPERTIES WILL_FAIL TRUE) + + set_property( + TEST readme_examples readme_examples_noexceptions readme_examples_will_fail_with_exceptions_off + APPEND PROPERTY LABELS quicktests + ) endif() + if(MSVC) add_custom_command(TARGET basictests POST_BUILD # Adds a post-build event COMMAND ${CMAKE_COMMAND} -E echo "$" diff --git a/scripts/issue150.sh b/tests/issue150.sh similarity index 100% rename from scripts/issue150.sh rename to tests/issue150.sh diff --git a/scripts/testjson2json.sh b/tests/testjson2json.sh similarity index 54% rename from scripts/testjson2json.sh rename to tests/testjson2json.sh index 085a991a..f511f9bb 100755 --- a/scripts/testjson2json.sh +++ b/tests/testjson2json.sh @@ -1,68 +1,39 @@ #!/bin/bash +set -e TMPDIR1=$(mktemp -d -t simdjsonXXXXXXXX) TMPDIR2=$(mktemp -d -t simdjsonXXXXXXXX) trap "exit 1" HUP INT PIPE QUIT TERM trap "rm -rf $TMPDIR1 $TMPDIR2" EXIT -function founderror() { - echo "code is wrong" - exit 1 -} - -make minify json2json -for i in `cd jsonexamples && ls -1 *.json`; do +echo "running json2json on jsonexamples and jsonchecker files (prints test successful on success) ..." +SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )" +JSONEXAMPLES=$SCRIPTPATH/../jsonexamples +JSONCHECKER=$SCRIPTPATH/../jsonchecker +for i in `cd $JSONEXAMPLES && ls -1 *.json`; do echo $i - ./json2json jsonexamples/$i > $TMPDIR1/$i + ./json2json $JSONEXAMPLES/$i > $TMPDIR1/$i ./json2json $TMPDIR1/$i > $TMPDIR2/$i cmp $TMPDIR1/$i $TMPDIR2/$i - retVal=$? - if [ $retVal -ne 0 ]; then - founderror - fi ./minify $TMPDIR1/$i > $TMPDIR1/minify$i ./minify $TMPDIR2/$i > $TMPDIR2/minify$i cmp $TMPDIR1/minify$i $TMPDIR2/minify$i - retVal=$? - if [ $retVal -ne 0 ]; then - founderror - fi ./json2json $TMPDIR1/minify$i > $TMPDIR2/bisminify$i cmp $TMPDIR1/$i $TMPDIR2/bisminify$i - retVal=$? - if [ $retVal -ne 0 ]; then - founderror - fi done -for i in `cd jsonchecker && ls -1 pass*.json`; do +for i in `cd $JSONCHECKER && ls -1 pass*.json`; do echo $i - ./json2json jsonchecker/$i > $TMPDIR1/$i + ./json2json $JSONCHECKER/$i > $TMPDIR1/$i ./json2json $TMPDIR1/$i > $TMPDIR2/$i cmp $TMPDIR1/$i $TMPDIR2/$i - retVal=$? - if [ $retVal -ne 0 ]; then - echo "reg failure" - founderror - fi - ./minify $TMPDIR1/$i > $TMPDIR1/minify$i ./minify $TMPDIR2/$i > $TMPDIR2/minify$i cmp $TMPDIR1/minify$i $TMPDIR2/minify$i - retVal=$? - if [ $retVal -ne 0 ]; then - echo "reg failure, step 2" - founderror - fi ./json2json $TMPDIR1/minify$i > $TMPDIR2/bisminify$i cmp $TMPDIR1/$i $TMPDIR2/bisminify$i - retVal=$? - if [ $retVal -ne 0 ]; then - founderror - fi done - echo "test successful" exit 0