Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Square brackets in test case name prevent ctest from running the test #1634

Closed
pinam45 opened this issue May 17, 2019 · 1 comment · Fixed by #1698
Closed

Square brackets in test case name prevent ctest from running the test #1634

pinam45 opened this issue May 17, 2019 · 1 comment · Fixed by #1698
Labels
Bug Extras Touches utility scripts outside of Catch2 proper, e.g. CMake integration.

Comments

@pinam45
Copy link

pinam45 commented May 17, 2019

Describe the bug

If a test case contain square brackets ([ and ]) in its name, then to call it with the executable you need to escape the brackets but ctest doesn't and the executable return 0 if no test were run.
So ctest call the test with the good name but without escaping the brackets, it doesn't run the test, return 0, ctest display success and you just think the test succeed (very tricky).

For me the problem is that is is not clear that there is a problem running the test, ctest just output that the test succeeded. If it is not possible to fix this problem from Catch2, I think it is necessary to at least warn about this in the documentation.

Expected behavior

Multiple possibilities:

  • Make the executable list test with correct call name (with escaped special characters) so the test can be called with a correct name by ctest.
  • Make the executable return something different from 0 when no test where run so it become clear that there is a problem when running ctest.
  • The documentation say: test name and section name are free form, quoted, strings, maybe forbid square brackets in test case names or just warn about the problem. (If it is already written in the documentation maybe it should be more clear because I couldn't find it.)

Maybe it is more a ctest problem, I don't know if there is this kind of problems with other testing frameworks.

Reproduction steps

Example with my repository, just remane the template test case "array subscript operator" to its old name "operator[]".

Manual test run:

$ ./dynamic_bitset_tests "operator[] - uint16_t" 
===============================================================================
No tests ran

It is clear, the test was not run. Easy to fix, escape the square brackets:

$ ./dynamic_bitset_tests "operator\[\] - uint16_t"
===============================================================================
All tests passed (11972 assertions in 1 test case)

Now let's use ctest:

$ ctest
...
      Start 42: count - uint64_t
42/81 Test #42: count - uint64_t .......................................   Passed    0.03 sec
      Start 43: operator[] - uint16_t
43/81 Test #43: operator[] - uint16_t ..................................   Passed    0.03 sec
      Start 44: operator[] - uint32_t
44/81 Test #44: operator[] - uint32_t ..................................   Passed    0.02 sec
      Start 45: operator[] - uint64_t
45/81 Test #45: operator[] - uint64_t ..................................   Passed    0.02 sec
      Start 46: size num_blocks empty capacity - uint16_t
46/81 Test #46: size num_blocks empty capacity - uint16_t ..............   Passed    0.03 sec
...

The test wasn't run but it is not indicated. I found it when adding code coverage, the code is not executed.

Platform information:

  • OS: Debian GNU/Linux buster/sid
  • Compiler+version: gcc (Debian 8.3.0-7) 8.3.0
  • ctest version: 3.13.4
  • Catch version: v2.7.2 (7c37501)
@sfranzen
Copy link
Contributor

You are right. Escaping brackets (and commas) is mentioned in the command line documentation, but the current CatchAddTests CMake module does this only for commas. I'll file a PR with a fix shortly.

@horenmar horenmar added Extras Touches utility scripts outside of Catch2 proper, e.g. CMake integration. Bug labels Jul 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Extras Touches utility scripts outside of Catch2 proper, e.g. CMake integration.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants