Add test tags as cmake label

This allows people running `cmake -L 'tag'` to run tests matching the tags
This commit is contained in:
Uy Ha 2023-05-21 15:02:17 +03:00
parent 733b901dd2
commit 064576520b

View File

@ -61,7 +61,7 @@ function(catch_discover_tests_impl)
endif() endif()
execute_process( execute_process(
COMMAND ${_TEST_EXECUTOR} "${_TEST_EXECUTABLE}" ${spec} --list-tests --verbosity quiet COMMAND ${_TEST_EXECUTOR} "${_TEST_EXECUTABLE}" ${spec} --list-tests --verbosity normal
OUTPUT_VARIABLE output OUTPUT_VARIABLE output
RESULT_VARIABLE result RESULT_VARIABLE result
WORKING_DIRECTORY "${_TEST_WORKING_DIR}" WORKING_DIRECTORY "${_TEST_WORKING_DIR}"
@ -78,7 +78,11 @@ function(catch_discover_tests_impl)
# that'd break the foreach loop for "Parse output" later and create # that'd break the foreach loop for "Parse output" later and create
# wrongly splitted and thus failing test cases (false positives) # wrongly splitted and thus failing test cases (false positives)
string(REPLACE ";" "\;" output "${output}") string(REPLACE ";" "\;" output "${output}")
string(STRIP "${output}" output)
string(REPLACE "\n" ";" output "${output}") string(REPLACE "\n" ";" output "${output}")
list(LENGTH output length)
math(EXPR length "${length} - 2")
list(SUBLIST output 1 "${length}" output)
# Prepare reporter # Prepare reporter
if(reporter) if(reporter)
@ -123,44 +127,57 @@ function(catch_discover_tests_impl)
# Parse output # Parse output
foreach(line ${output}) foreach(line ${output})
set(test "${line}") if(line MATCHES "^ ([^ ].*)$")
# Escape characters in test case names that would be parsed by Catch2 set(test ${line})
# Note that the \ escaping must happen FIRST! Do not change the order. # Escape characters in test case names that would be parsed by Catch2
set(test_name "${test}") # Note that the \ escaping must happen FIRST! Do not change the order.
foreach(char \\ , [ ]) set(test_name ${test})
string(REPLACE ${char} "\\${char}" test_name "${test_name}") foreach(char \\ , [ ])
endforeach(char) string(REPLACE ${char} "\\${char}" test_name ${test_name})
# ...add output dir endforeach(char)
if(output_dir) # ...add output dir
string(REGEX REPLACE "[^A-Za-z0-9_]" "_" test_name_clean "${test_name}") if(output_dir)
set(output_dir_arg "--out ${output_dir}/${output_prefix}${test_name_clean}${output_suffix}") string(REGEX REPLACE "[^A-Za-z0-9_]" "_" test_name_clean ${test_name})
endif() set(output_dir_arg "--out ${output_dir}/${output_prefix}${test_name_clean}${output_suffix}")
endif()
# ...and add to script # ...and add to script
add_command(add_test add_command(add_test
"${prefix}${test}${suffix}" "${prefix}${test}${suffix}"
${_TEST_EXECUTOR} ${_TEST_EXECUTOR}
"${_TEST_EXECUTABLE}" "${_TEST_EXECUTABLE}"
"${test_name}" "${test_name}"
${extra_args} ${extra_args}
"${reporter_arg}" "${reporter_arg}"
"${output_dir_arg}" "${output_dir_arg}"
) )
add_command(set_tests_properties
"${prefix}${test}${suffix}"
PROPERTIES
WORKING_DIRECTORY "${_TEST_WORKING_DIR}"
${properties}
)
if(environment_modifications)
add_command(set_tests_properties add_command(set_tests_properties
"${prefix}${test}${suffix}" "${prefix}${test}${suffix}"
PROPERTIES PROPERTIES
ENVIRONMENT_MODIFICATION "${environment_modifications}") WORKING_DIRECTORY "${_TEST_WORKING_DIR}"
endif() ${properties}
)
list(APPEND tests "${prefix}${test}${suffix}") if(environment_modifications)
add_command(set_tests_properties
"${prefix}${test}${suffix}"
PROPERTIES
ENVIRONMENT_MODIFICATION "${environment_modifications}")
endif()
list(APPEND tests "${prefix}${test}${suffix}")
elseif(line MATCHES "^ (.*)$")
set(tags "${CMAKE_MATCH_1}")
string(REGEX REPLACE "^\\[" "" tags "${tags}")
string(REGEX REPLACE "\\]$" "" tags "${tags}")
string(REPLACE "][" ";" tags "${tags}")
add_command(set_tests_properties
"${prefix}${test}${suffix}"
PROPERTIES
LABELS "${tags}"
)
endif()
endforeach() endforeach()
# Create a list of all discovered tests, which users may use to e.g. set # Create a list of all discovered tests, which users may use to e.g. set