Skip to content

Commit

Permalink
Fix handling of semicolon and backslash characters in CMake test disc…
Browse files Browse the repository at this point in the history
…overy
  • Loading branch information
robinchrist committed Apr 19, 2023
1 parent 9a2a4ea commit 2c9efc5
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions extras/CatchAddTests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 2c9efc5

Please sign in to comment.