CatchAddTests now adds tags as labels for ctest

- `ctest --print-labels` now will show list of available labels
- `ctest -L <regex>` will allow to run tests with given labels(tags)
This commit is contained in:
Maciej Patro 2019-04-13 15:47:14 +02:00 committed by Martin Hořeňovský
parent 36fb856163
commit d4eec016a9
1 changed files with 47 additions and 19 deletions

View File

@ -22,6 +22,39 @@ function(add_command NAME)
set(script "${script}${NAME}(${_args})\n" PARENT_SCOPE) set(script "${script}${NAME}(${_args})\n" PARENT_SCOPE)
endfunction() endfunction()
macro(_add_catch_test_labels LINE)
# convert to list of tags
string(REPLACE "][" "]\\;[" tags ${line})
add_command(
set_tests_properties "${prefix}${test}${suffix}"
PROPERTIES
LABELS "${tags}"
)
endmacro()
macro(_add_catch_test LINE)
set(test ${line})
# use escape commas to handle properly test cases with commans inside the name
string(REPLACE "," "\\," test_name ${test})
# ...and add to script
add_command(
add_test "${prefix}${test}${suffix}"
${TEST_EXECUTOR}
"${TEST_EXECUTABLE}"
"${test_name}"
${extra_args}
)
add_command(
set_tests_properties "${prefix}${test}${suffix}"
PROPERTIES
WORKING_DIRECTORY "${TEST_WORKING_DIR}"
${properties}
)
list(APPEND tests "${prefix}${test}${suffix}")
endmacro()
# Run test executable to get list of available tests # Run test executable to get list of available tests
if(NOT EXISTS "${TEST_EXECUTABLE}") if(NOT EXISTS "${TEST_EXECUTABLE}")
message(FATAL_ERROR message(FATAL_ERROR
@ -29,7 +62,7 @@ if(NOT EXISTS "${TEST_EXECUTABLE}")
) )
endif() endif()
execute_process( execute_process(
COMMAND ${TEST_EXECUTOR} "${TEST_EXECUTABLE}" ${spec} --list-test-names-only COMMAND ${TEST_EXECUTOR} "${TEST_EXECUTABLE}" ${spec} --list-tests
OUTPUT_VARIABLE output OUTPUT_VARIABLE output
RESULT_VARIABLE result RESULT_VARIABLE result
) )
@ -47,27 +80,22 @@ elseif(${result} LESS 0)
endif() endif()
string(REPLACE "\n" ";" output "${output}") string(REPLACE "\n" ";" output "${output}")
set(test)
set(tags_regex "(\\[([^\\[]*)\\])+$")
# Parse output # Parse output
foreach(line ${output}) foreach(line ${output})
set(test ${line}) # lines without leading whitespaces are catch output not tests
# use escape commas to handle properly test cases with commans inside the name if(${line} MATCHES "^[ \t]+")
string(REPLACE "," "\\," test_name ${test}) # strip leading spaces and tabs
# ...and add to script string(REGEX REPLACE "^[ \t]+" "" line ${line})
add_command(add_test
"${prefix}${test}${suffix}" if(${line} MATCHES "${tags_regex}")
${TEST_EXECUTOR} _add_catch_test_labels(${line})
"${TEST_EXECUTABLE}" else()
"${test_name}" _add_catch_test(${line})
${extra_args} endif()
) endif()
add_command(set_tests_properties
"${prefix}${test}${suffix}"
PROPERTIES
WORKING_DIRECTORY "${TEST_WORKING_DIR}"
${properties}
)
list(APPEND tests "${prefix}${test}${suffix}")
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