0

I'm using CMake's 3.18 CTest with the Catch2 3.1.1 framework for testing purposes, and am currently having problems finding what the valid characters are in Catch2's macro TEST_CASE's name parameter.

For instance, I created a test case

TEST_CASE("Use mask '1:2;3:4'"){...}

and ran ctest in the command prompt, I get

1/1 Test 1: Use mask '1:2 ................ Failed 0.09 sec.

If I run ctest with the -V option, I can see it's trying to run test.exe "Use mask '1:2", which returns "No test cases matched.", and therefore fails.

So it looks like the semicolon in the name is messing things up.

Similarly, for test case

TEST_CASE("set prefix \\x"){...}

I get

1/1 Test 1: set prefix \x ................ Failed 0.09 sec.

Running ctest -V, it runs test_2.exe "set prefix \x", which again returns "No test cases matched.".

Removing the underscore in the first test case and double backslash in the second test case fixed the issue. I haven't found a solution online, Catch2 docs say the test case name is a free-form string, but that's about it, which doesn't help me.

user3007875
  • 123
  • 7
  • 2
    "Catch2 docs say the test case name is a free-form string" - But in CMake 3.18 [add_test](https://cmake.org/cmake/help/v3.18/command/add_test.html) command doesn't support special characters. Only in CMake 3.19 the restriction has been [relaxed](https://cmake.org/cmake/help/latest/command/add_test.html). Probably, this is the reason of your problems. – Tsyvarev Nov 10 '22 at 17:36
  • @Tsyvarev Thanks for your help. Yes, I checked the add_test() documentation, but it also says the NAME may not contain spaces. But for me, spaces work ok. So I am a bit confused about that. – user3007875 Nov 11 '22 at 10:02
  • 2
    Description in `add_test` "The test name may not contain spaces, quotes, or other characters special in CMake syntax." is a **precondition** for the **user** of the function. If a user (e.g. Catch2) violates a precondition, then **any thing could happen**: It could work like in a correct case. It could emit an error. It could fail in a weird way. It could work on one platform but fail on another one. It could work in one CMake version but fail in another version... Normally, a **precondition** cannot be *deduced* from the code: it should be **stated** in documentation or in other manual. – Tsyvarev Nov 11 '22 at 10:12
  • @Tsyvarev Thanks for the help, I looked at it again and read the policy CMP0110, which explains why i get problems. – user3007875 Nov 14 '22 at 10:53

0 Answers0