From 2c9efc543e903d68d3d95f75c68b63b5d4b9749f Mon Sep 17 00:00:00 2001 From: Robin Christ Date: Wed, 19 Apr 2023 11:42:56 +0200 Subject: [PATCH] Fix handling of semicolon and backslash characters in CMake test discovery --- extras/CatchAddTests.cmake | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/extras/CatchAddTests.cmake b/extras/CatchAddTests.cmake index 2df663dc1d..008756c2c3 100644 --- a/extras/CatchAddTests.cmake +++ b/extras/CatchAddTests.cmake @@ -64,6 +64,9 @@ if(NOT ${result} EQUAL 0) ) 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 @@ -109,15 +112,16 @@ endif() # 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()