From 7b8aec14551afe61f7fb07852dd7f9aa62785099 Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Thu, 14 Jul 2022 09:44:58 +0200 Subject: [PATCH 1/2] CMake: Add TEST_PROPERTIES to json_test_set_test_options() Allow overriding test properties via json_test_set_test_options(). --- cmake/test.cmake | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/cmake/test.cmake b/cmake/test.cmake index b8b1250fb7..bb840c6c00 100644 --- a/cmake/test.cmake +++ b/cmake/test.cmake @@ -50,9 +50,10 @@ endforeach() # [COMPILE_FEATURES ...] # [COMPILE_OPTIONS ...] # [LINK_LIBRARIES ...] -# [LINK_OPTIONS ...]) +# [LINK_OPTIONS ...] +# [TEST_PROPERTIES ...]) # -# Supply test- and standard-specific build settings. +# Supply test- and standard-specific build settings and/or test properties. # Specify multiple tests using a list e.g., "test-foo;test-bar". # # Must be called BEFORE the test is created. @@ -60,7 +61,7 @@ endforeach() function(json_test_set_test_options tests) cmake_parse_arguments(args "" "" - "CXX_STANDARDS;COMPILE_DEFINITIONS;COMPILE_FEATURES;COMPILE_OPTIONS;LINK_LIBRARIES;LINK_OPTIONS" + "CXX_STANDARDS;COMPILE_DEFINITIONS;COMPILE_FEATURES;COMPILE_OPTIONS;LINK_LIBRARIES;LINK_OPTIONS;TEST_PROPERTIES" ${ARGN}) if(NOT args_CXX_STANDARDS) @@ -91,10 +92,23 @@ function(json_test_set_test_options tests) target_compile_options(${test_interface} INTERFACE ${args_COMPILE_OPTIONS}) target_link_libraries (${test_interface} INTERFACE ${args_LINK_LIBRARIES}) target_link_options(${test_interface} INTERFACE ${args_LINK_OPTIONS}) + #set_target_properties(${test_interface} PROPERTIES JSON_TEST_PROPERTIES "${args_TEST_PROPERTIES}") + set_property(DIRECTORY PROPERTY + ${test_interface}_TEST_PROPERTIES "${args_TEST_PROPERTIES}" + ) endforeach() endforeach() endfunction() +# for internal use by _json_test_add_test() +function(_json_test_apply_test_properties test_target properties_target) + #get_target_property(test_properties ${properties_target} JSON_TEST_PROPERTIES) + get_property(test_properties DIRECTORY PROPERTY ${properties_target}_TEST_PROPERTIES) + if(test_properties) + set_tests_properties(${test_target} PROPERTIES ${test_properties}) + endif() +endfunction() + # for internal use by json_test_add_test_for() function(_json_test_add_test test_name file main cxx_standard) set(test_target ${test_name}_cpp${cxx_standard}) @@ -142,6 +156,23 @@ function(_json_test_add_test test_name file main cxx_standard) endif() set_tests_properties(${test_target} PROPERTIES LABELS "all" FIXTURES_REQUIRED TEST_DATA) + # apply standard-specific test properties + if(TARGET _json_test_interface__cpp_${cxx_standard}) + _json_test_apply_test_properties(${test_target} _json_test_interface__cpp_${cxx_standard}) + endif() + + # apply test-specific test properties + if(TARGET _json_test_interface_${test_name}) + _json_test_apply_test_properties(${test_target} _json_test_interface_${test_name}) + endif() + + # apply test- and standard-specific test properties + if(TARGET _json_test_interface_${test_name}_cpp_${cxx_standard}) + _json_test_apply_test_properties(${test_target} + _json_test_interface_${test_name}_cpp_${cxx_standard} + ) + endif() + if(JSON_Valgrind) add_test(NAME ${test_target}_valgrind COMMAND ${memcheck_command} $ ${DOCTEST_TEST_FILTER} From 90b56747e0244fd7101168e6eda06b4e3a816fc0 Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Thu, 14 Jul 2022 09:50:04 +0200 Subject: [PATCH 2/2] CMake: Set timeouts for Unicode tests --- tests/CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8f9240f1ae..a664f4bafd 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -80,12 +80,17 @@ endif() # disable exceptions for test-disabled_exceptions json_test_set_test_options(test-disabled_exceptions COMPILE_DEFINITIONS JSON_NOEXCEPTION) if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU") -json_test_set_test_options(test-disabled_exceptions COMPILE_OPTIONS -fno-exceptions) + json_test_set_test_options(test-disabled_exceptions COMPILE_OPTIONS -fno-exceptions) elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") # disabled due to https://github.com/nlohmann/json/discussions/2824 #json_test_set_test_options(test-disabled_exceptions COMPILE_DEFINITIONS _HAS_EXCEPTIONS=0 COMPILE_OPTIONS /EH) endif() +# set timeouts for Unicode tests +json_test_set_test_options("test-unicode2;test-unicode3;test-unicode4;test-unicode5" + TEST_PROPERTIES "TIMEOUT_AFTER_MATCH;1500$UTF-8 strings checked" +) + ############################################################################# # add unit tests #############################################################################