1 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
4 set(prefix "${TEST_PREFIX}")
5 set(suffix "${TEST_SUFFIX}")
7 set(extra_args ${TEST_EXTRA_ARGS})
8 set(properties ${TEST_PROPERTIES})
13 function(add_command NAME)
16 if(_arg MATCHES "[^-./:a-zA-Z0-9_]")
17 set(_args "${_args} [==[${_arg}]==]") # form a bracket_argument
19 set(_args "${_args} ${_arg}")
22 set(script "${script}${NAME}(${_args})\n" PARENT_SCOPE)
25 # Run test executable to get list of available tests
26 if(NOT EXISTS "${TEST_EXECUTABLE}")
28 "Specified test executable '${TEST_EXECUTABLE}' does not exist"
32 COMMAND ${TEST_EXECUTOR} "${TEST_EXECUTABLE}" ${spec} --list-test-names-only
33 OUTPUT_VARIABLE output
34 RESULT_VARIABLE result
36 # Catch --list-test-names-only reports the number of tests, so 0 is... surprising
39 "Test executable '${TEST_EXECUTABLE}' contains no tests!\n"
41 elseif(${result} LESS 0)
43 "Error running test executable '${TEST_EXECUTABLE}':\n"
44 " Result: ${result}\n"
45 " Output: ${output}\n"
49 string(REPLACE "\n" ";" output "${output}")
52 foreach(line ${output})
54 # Escape characters in test case names that would be parsed by Catch2
55 set(test_name ${test})
57 string(REPLACE ${char} "\\${char}" test_name ${test_name})
59 # ...and add to script
61 "${prefix}${test}${suffix}"
67 add_command(set_tests_properties
68 "${prefix}${test}${suffix}"
70 WORKING_DIRECTORY "${TEST_WORKING_DIR}"
73 list(APPEND tests "${prefix}${test}${suffix}")
76 # Create a list of all discovered tests, which users may use to e.g. set
77 # properties on the tests
78 add_command(set ${TEST_LIST} ${tests})
81 file(WRITE "${CTEST_FILE}" "${script}")