diff options
author | Brad King <brad.king@kitware.com> | 2022-01-12 14:44:18 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2022-01-12 14:44:24 (GMT) |
commit | c7af95477038cdf90b8ebfeb2ac0beae14aff5d9 (patch) | |
tree | c966b788dd651b9d92989a09dee1df97aed82c2d /Modules | |
parent | 34d16d9e56541dad3b9aa2fc45e271cbb08b3097 (diff) | |
parent | 8b85b10fb36e5d1ef4d639cd841cf637d64df3c8 (diff) | |
download | CMake-c7af95477038cdf90b8ebfeb2ac0beae14aff5d9.zip CMake-c7af95477038cdf90b8ebfeb2ac0beae14aff5d9.tar.gz CMake-c7af95477038cdf90b8ebfeb2ac0beae14aff5d9.tar.bz2 |
Merge topic 'GoogleTest-discover-sq-brackets'
8b85b10fb3 GoogleTest: Add handling for square brackets in test names
8f977a5c92 GoogleTest: Generalize test samples
Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !6842
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/GoogleTestAddTests.cmake | 68 |
1 files changed, 55 insertions, 13 deletions
diff --git a/Modules/GoogleTestAddTests.cmake b/Modules/GoogleTestAddTests.cmake index 1283a3f..7043b2b 100644 --- a/Modules/GoogleTestAddTests.cmake +++ b/Modules/GoogleTestAddTests.cmake @@ -20,7 +20,7 @@ macro(flush_tests_buffer) set(tests_buffer "") endmacro() -macro(add_command NAME) +macro(add_command NAME TEST_NAME) set(_args "") foreach(_arg ${ARGN}) if(_arg MATCHES "[^-./:a-zA-Z0-9_]") @@ -29,7 +29,7 @@ macro(add_command NAME) string(APPEND _args " ${_arg}") endif() endforeach() - string(APPEND script "${NAME}(${_args})\n") + string(APPEND script "${NAME}(${TEST_NAME} ${_args})\n") string(LENGTH "${script}" _script_len) if(${_script_len} GREATER "50000") flush_script() @@ -39,6 +39,32 @@ macro(add_command NAME) unset(_script_len) endmacro() +function(generate_testname_guards OUTPUT OPEN_GUARD_VAR CLOSE_GUARD_VAR) + set(open_guard "[=[") + set(close_guard "]=]") + set(counter 1) + while("${OUTPUT}" MATCHES "${close_guard}") + math(EXPR counter "${counter} + 1") + string(REPEAT "=" ${counter} equals) + set(open_guard "[${equals}[") + set(close_guard "]${equals}]") + endwhile() + set(${OPEN_GUARD_VAR} "${open_guard}" PARENT_SCOPE) + set(${CLOSE_GUARD_VAR} "${close_guard}" PARENT_SCOPE) +endfunction() + +function(escape_square_brackets OUTPUT BRACKET PLACEHOLDER PLACEHOLDER_VAR OUTPUT_VAR) + if("${OUTPUT}" MATCHES "\\${BRACKET}") + set(placeholder "${PLACEHOLDER}") + while("${OUTPUT}" MATCHES "${placeholder}") + set(placeholder "${placeholder}_") + endwhile() + string(REPLACE "${BRACKET}" "${placeholder}" OUTPUT "${OUTPUT}") + set(${PLACEHOLDER_VAR} "${placeholder}" PARENT_SCOPE) + set(${OUTPUT_VAR} "${OUTPUT}" PARENT_SCOPE) + endif() +endfunction() + function(gtest_discover_tests_impl) cmake_parse_arguments( @@ -94,6 +120,9 @@ function(gtest_discover_tests_impl) ) endif() + generate_testname_guards("${output}" open_guard close_guard) + escape_square_brackets("${output}" "[" "__osb" open_sb output) + escape_square_brackets("${output}" "]" "__csb" close_sb output) # Preserve semicolon in test-parameters string(REPLACE [[;]] [[\;]] output "${output}") string(REPLACE "\n" ";" output "${output}") @@ -128,18 +157,24 @@ function(gtest_discover_tests_impl) unset(TEST_XML_OUTPUT_PARAM) endif() - # sanitize test name for further processing downstream set(testname "${prefix}${pretty_suite}.${pretty_test}${suffix}") + # sanitize test name for further processing downstream + # unescape [] + if(open_sb) + string(REPLACE "${open_sb}" "[" testname "${testname}") + endif() + if(close_sb) + string(REPLACE "${close_sb}" "]" testname "${testname}") + endif() # escape \ string(REPLACE [[\]] [[\\]] testname "${testname}") - # escape ; - string(REPLACE [[;]] [[\;]] testname "${testname}") # escape $ string(REPLACE [[$]] [[\$]] testname "${testname}") + set(guarded_testname "${open_guard}${testname}${close_guard}") # ...and add to script add_command(add_test - "${testname}" + "${guarded_testname}" ${_TEST_EXECUTOR} "${_TEST_EXECUTABLE}" "--gtest_filter=${suite}.${test}" @@ -149,21 +184,28 @@ function(gtest_discover_tests_impl) ) if(suite MATCHES "^DISABLED_" OR test MATCHES "^DISABLED_") add_command(set_tests_properties - "${testname}" + "${guarded_testname}" PROPERTIES DISABLED TRUE ) endif() + add_command(set_tests_properties - "${testname}" + "${guarded_testname}" PROPERTIES WORKING_DIRECTORY "${_TEST_WORKING_DIR}" SKIP_REGULAR_EXPRESSION "\\\\[ SKIPPED \\\\]" ${properties} ) - list(APPEND tests_buffer "${testname}") - list(LENGTH tests_buffer tests_buffer_length) - if(${tests_buffer_length} GREATER "250") - flush_tests_buffer() + + # possibly unbalanced square brackets render lists invalid so skip such tests in _TEST_LIST + if(NOT "${testname}" MATCHES [=[(\[|\])]=]) + # escape ; + string(REPLACE [[;]] [[\;]] testname "${testname}") + list(APPEND tests_buffer "${testname}") + list(LENGTH tests_buffer tests_buffer_length) + if(${tests_buffer_length} GREATER "250") + flush_tests_buffer() + endif() endif() endif() endif() @@ -173,7 +215,7 @@ function(gtest_discover_tests_impl) # Create a list of all discovered tests, which users may use to e.g. set # properties on the tests flush_tests_buffer() - add_command(set ${_TEST_LIST} ${tests}) + add_command(set "" ${_TEST_LIST} ${tests}) # Write CTest script flush_script() |