diff --git a/extras/CatchAddTests.cmake b/extras/CatchAddTests.cmake index 692e340566..996492271a 100644 --- a/extras/CatchAddTests.cmake +++ b/extras/CatchAddTests.cmake @@ -61,7 +61,7 @@ function(catch_discover_tests_impl) endif() execute_process( - COMMAND ${_TEST_EXECUTOR} "${_TEST_EXECUTABLE}" ${spec} --list-tests --verbosity quiet + COMMAND ${_TEST_EXECUTOR} "${_TEST_EXECUTABLE}" ${spec} --list-tests --reporter JSON OUTPUT_VARIABLE output RESULT_VARIABLE result WORKING_DIRECTORY "${_TEST_WORKING_DIR}" @@ -74,12 +74,6 @@ function(catch_discover_tests_impl) ) 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 if(reporter) set(reporter_arg "--reporter ${reporter}") @@ -121,9 +115,15 @@ function(catch_discover_tests_impl) endforeach() endif() + string(JSON listings GET "${output}" "listings") + string(JSON tests GET "${listings}" "tests") + string(JSON tests_length LENGTH "${tests}") + # CMake foreach loop is inclusive + math(EXPR test_end "${tests_length} - 1") # Parse output - foreach(line ${output}) - set(test "${line}") + foreach(index RANGE "${test_end}") + string(JSON test_spec GET "${tests}" "${index}") + string(JSON test GET "${test_spec}" "name") # Escape characters in test case names that would be parsed by Catch2 # Note that the \ escaping must happen FIRST! Do not change the order. set(test_name "${test}") @@ -161,6 +161,22 @@ function(catch_discover_tests_impl) endif() list(APPEND tests "${prefix}${test}${suffix}") + + string(JSON tags GET "${test_spec}" "tags") + string(JSON tags_length LENGTH "${tags}") + + if("${tags_length}" GREATER 0) + math(EXPR tag_end "${tags_length} - 1") + + foreach(tag_index RANGE "${tag_end}") + string(JSON tag GET "${tags}" "${tag_index}") + add_command(set_tests_properties + "${prefix}${test}${suffix}" + PROPERTIES + LABELS "${tags}" + ) + endforeach() + endif() endforeach() # Create a list of all discovered tests, which users may use to e.g. set