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
This commit is contained in:
Robin Christ 2023-06-14 23:40:10 +02:00 committed by GitHub
parent a0c6a28460
commit 42ee66b5e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

View File

@ -74,6 +74,10 @@ function(catch_discover_tests_impl)
) )
endif() 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}") string(REPLACE "\n" ";" output "${output}")
# Prepare reporter # Prepare reporter
@ -119,15 +123,16 @@ function(catch_discover_tests_impl)
# Parse output # Parse output
foreach(line ${output}) foreach(line ${output})
set(test ${line}) set(test "${line}")
# Escape characters in test case names that would be parsed by Catch2 # Escape characters in test case names that would be parsed by Catch2
set(test_name ${test}) # Note that the \ escaping must happen FIRST! Do not change the order.
foreach(char , [ ]) set(test_name "${test}")
string(REPLACE ${char} "\\${char}" test_name ${test_name}) foreach(char \\ , [ ])
string(REPLACE ${char} "\\${char}" test_name "${test_name}")
endforeach(char) endforeach(char)
# ...add output dir # ...add output dir
if(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}") set(output_dir_arg "--out ${output_dir}/${output_prefix}${test_name_clean}${output_suffix}")
endif() endif()

View File

@ -8,4 +8,5 @@
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
TEST_CASE("@Script[C:\\EPM1A]=x;\"SCALA_ZERO:\"", "[script regressions]"){}
TEST_CASE("Some test") {} TEST_CASE("Some test") {}