diff options
| author | Robin Christ | 2023-06-14 23:40:10 +0200 |
|---|---|---|
| committer | GitHub | 2023-06-14 23:40:10 +0200 |
| commit | 42ee66b5e625b7ed43727e3617af58ca8fad4a12 (patch) | |
| tree | 30522463da2f2a9014fb8a518ad08a8040f4945c | |
| parent | a0c6a28460872bfbdbc2ffc4c7ad19f352343586 (diff) | |
| download | catch3-42ee66b5e625b7ed43727e3617af58ca8fad4a12.tar.gz | |
Fix handling of semicolon and backslash characters in CMake test discovery (#2676)
This PR fixes the handling of semicolon and backslash characters in test names in the CMake test discovery
Closes #2674
| -rw-r--r-- | extras/CatchAddTests.cmake | 15 | ||||
| -rw-r--r-- | tests/TestScripts/DiscoverTests/register-tests.cpp | 1 |
2 files changed, 11 insertions, 5 deletions
diff --git a/extras/CatchAddTests.cmake b/extras/CatchAddTests.cmake index 91f79f3c..46d7a2a9 100644 --- a/extras/CatchAddTests.cmake +++ b/extras/CatchAddTests.cmake @@ -74,6 +74,10 @@ function(catch_discover_tests_impl) ) endif() + # Make sure to escape ; (semicolons) in test names first, because + # that'd break the foreach loop for "Parse output" later and create + # wrongly splitted and thus failing test cases (false positives) + string(REPLACE ";" "\;" output "${output}") string(REPLACE "\n" ";" output "${output}") # Prepare reporter @@ -119,15 +123,16 @@ function(catch_discover_tests_impl) # Parse output foreach(line ${output}) - set(test ${line}) + set(test "${line}") # Escape characters in test case names that would be parsed by Catch2 - set(test_name ${test}) - foreach(char , [ ]) - string(REPLACE ${char} "\\${char}" test_name ${test_name}) + # Note that the \ escaping must happen FIRST! Do not change the order. + set(test_name "${test}") + foreach(char \\ , [ ]) + string(REPLACE ${char} "\\${char}" test_name "${test_name}") endforeach(char) # ...add output dir if(output_dir) - string(REGEX REPLACE "[^A-Za-z0-9_]" "_" test_name_clean ${test_name}) + string(REGEX REPLACE "[^A-Za-z0-9_]" "_" test_name_clean "${test_name}") set(output_dir_arg "--out ${output_dir}/${output_prefix}${test_name_clean}${output_suffix}") endif() diff --git a/tests/TestScripts/DiscoverTests/register-tests.cpp b/tests/TestScripts/DiscoverTests/register-tests.cpp index 91382eaa..21238d59 100644 --- a/tests/TestScripts/DiscoverTests/register-tests.cpp +++ b/tests/TestScripts/DiscoverTests/register-tests.cpp @@ -8,4 +8,5 @@ #include <catch2/catch_test_macros.hpp> +TEST_CASE("@Script[C:\\EPM1A]=x;\"SCALA_ZERO:\"", "[script regressions]"){} TEST_CASE("Some test") {} |