Skip to content

Commit 8df812f

Browse files
committed
WIP: fix registration bug
1 parent 4cde128 commit 8df812f

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

extras/CatchAddTests.cmake

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ function(catch_discover_tests_impl)
221221
set(script)
222222
set(suite)
223223
set(tests)
224+
# Holds the list of all registered test names **as a string**, not list.
225+
# This avoids issue of CMake removing semicolon escapes even inside
226+
# bracket-quoted strings.
227+
set(_test_names)
224228

225229
if(WIN32)
226230
set(dl_paths_variable_name PATH)
@@ -431,13 +435,23 @@ function(catch_discover_tests_impl)
431435
string(APPEND script "${_Command}")
432436
endif()
433437

434-
list(APPEND tests "${prefix}${plain_name}${suffix}")
438+
# The test name has to be escaped using the same rules as prepare_command
439+
# uses for the arguments, so that it keeps being single element in list
440+
# even with weird characters and semicolons.
441+
set(full_list_name "${prefix}${plain_name}${suffix}")
442+
string(REPLACE ";" "\\;" full_list_name "${full_list_name}")
443+
if(full_list_name MATCHES "[^-./:a-zA-Z0-9_]")
444+
# The space before the start of quote is important, so that we get
445+
# space-separated list in the final file.
446+
string(APPEND _test_names " [==[${full_list_name}]==]")
447+
else()
448+
string(APPEND _test_names " ${full_list_name}")
449+
endif()
435450
endforeach()
436451

437452
# Create a list of all discovered tests, which users may use to e.g. set
438453
# properties on the tests
439-
prepare_command(set ${_TEST_LIST} ${tests})
440-
string(APPEND script "${_Command}")
454+
string(APPEND script "set(${_TEST_LIST}${_test_names})\n")
441455

442456
# Write any script leftovers we have
443457
file(APPEND "${_CTEST_FILE}" "${script}")

tests/TestScripts/DiscoverTests/register-tests.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ class TestCaseFixture {
4040

4141
TEST_CASE_METHOD(TestCaseFixture, "A test case as method", "[tagstagstags]") {}
4242

43+
TEST_CASE("Unclosed right ) parenthesis") {}
44+
TEST_CASE("Unclosed left ( parenthesis") {}
45+
4346
TEST_CASE( "Newlines\nAnd\rOther\n\tWhitespace", "[whitespace-going-wild]" ) {}
4447

4548
// Some JSON-like and JSON-adjacent characters and substrings in the test names/tags

0 commit comments

Comments
 (0)