You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
One of our working students has created several test cases for the parser of a custom DSL which often contains ; (semicolon) and Windows-style file paths in expressions and has named them after the expression that is being tested if short enough, e.g.
If we take the part @Script\[C:\EPM1A\]=x;"SCALA_ZERO:" and do test-binary '@Script\[C:\EPM1A\]=x;"SCALA_ZERO:"' we will get:
No tests ran
Uh oh!
Well, there's another issue: \ in test names are not properly escaped.
We need to change foreach(char , [ ]) to foreach(char \\ , [ ]) Note that the order is important: The replacement of \ needs to happen first!
Additionally, the strings must be handles correctly (i.e. set in quotes everywhere to preserve the ;, otherwise CMake will do funny list stuff...)
So in total this looks like:
string(REPLACE ";" "\;" output "${output}")
string(REPLACE "\n" ";" output "${output}")
...
# Parse output
foreach(line ${output})
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}")
endforeach(char)
# ...add output dir
if(output_dir)
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()
Expected behavior
Only a single test should be created
Reproduction steps
Create a test case containing a semicolon in its name and use the CMake integration, e.g.
Describe the bug
One of our working students has created several test cases for the parser of a custom DSL which often contains
;
(semicolon) and Windows-style file paths in expressions and has named them after the expression that is being tested if short enough, e.g.This leads to the creation of a lot of wrong test cases, potentially leading to false positives:
This can also be seen in the corresponding
tests-<hash>-cmake
:By adding some debug logging to
CatchAddTests.cmake
, we can see that it's a bug in theforeach
logic:Debug log statements:
I believe this is due to
Catch2/extras/CatchAddTests.cmake
Line 67 in 9a2a4ea
Obviously, if the test case name already contains
;
, the test case will be split and it won't work.seems to fix this.
One thing we can also see in the resulting output file (one we have applied the fix above):
If we take the part
@Script\[C:\EPM1A\]=x;"SCALA_ZERO:"
and dotest-binary '@Script\[C:\EPM1A\]=x;"SCALA_ZERO:"'
we will get:Uh oh!
Well, there's another issue:
\
in test names are not properly escaped.We need to change
foreach(char , [ ])
toforeach(char \\ , [ ])
Note that the order is important: The replacement of
\
needs to happen first!Additionally, the strings must be handles correctly (i.e. set in quotes everywhere to preserve the
;
, otherwise CMake will do funny list stuff...)So in total this looks like:
Expected behavior
Only a single test should be created
Reproduction steps
Create a test case containing a semicolon in its name and use the CMake integration, e.g.
Platform information:
CMake 3.22.2
Catch2 v3.3.2
Additional context
Sorry, I added the backslashes part later, so this is all a bit incoherent...
I should probably create a pull request with the fixed code?
The text was updated successfully, but these errors were encountered: