Catch2 icon indicating copy to clipboard operation
Catch2 copied to clipboard

catch_discover_tests(): Trailing spaces in TEST_PREFIX get lost

Open moha-gh opened this issue 5 years ago • 1 comments

Describe the bug

I'd like to prefix the name of our test cases with the name of the test executable itself (1) via TEST_PREFIX:

catch_discover_tests(
    ${TARGET}
    TEST_PREFIX "${TARGET} "
    [...]
)

The trailing space however gets lost, yielding <target><test name> instead of <target> <test name>.

(1): So we are able to easily identify where a test comes from in the huge test list printed by ctest during execution without using SCENARIO("MyClass: foo bar ...") instead of SCENARIO("foo bar ...") everywhere.

Expected behavior

The trailing space is not lost, but included in the final test name(s) generated by catch_discover_tests().

The issue seems to be caused by the escaping in the argument list of the add_custom_command() inside catch_discover_tests().

Original:

-D "TEST_PREFIX=${_TEST_PREFIX}"

Works:

-D "TEST_PREFIX='${_TEST_PREFIX}'"

Also works and nicer IMO (the doubles quotes are added back automatically by CMake thanks to the VERBATIM option:

-D TEST_PREFIX='${_TEST_PREFIX}'

I'd be happy to file a PR when it's clear which solution is the preferred one (and whether other variables passed along are also affected, but I don't think there are scenarios where the others would need trailing spaces).

Reproduction steps

See above

Platform information:

  • OS: Linux
  • Compiler+version: not relevant
  • CMake version: v3.10.3
  • Catch version: v2.13.4

Additional context

n/a

moha-gh avatar Jan 07 '21 07:01 moha-gh

I wonder if this is happening with the call to cmake_parse_arguments at the top of catch_discover_tests in extras/Catch.cmake.

EDIT. I tried a minimal example locally and I don't think that's the problem.

function(heyo)
	cmake_parse_arguments("" "" "A" "" ${ARGN})
	message("_A: ${_A}.")
endfunction()
heyo(A "    aa       !!!!!!!!!                 ")

david-fong avatar Aug 03 '22 08:08 david-fong