1 # Copyright (c) Facebook, Inc. and its affiliates.
3 # Add a command to be emitted to the CTest file
5 function(add_command CMD)
8 # Escape all arguments using "Bracket Argument" syntax
9 # We could skip this for argument that don't contain any special
10 # characters if we wanted to make the output slightly more human-friendly.
11 set(escaped_args "${escaped_args} [==[${arg}]==]")
13 set(ctest_script "${ctest_script}${CMD}(${escaped_args})\n" PARENT_SCOPE)
16 if(NOT EXISTS "${TEST_EXECUTABLE}")
17 message(FATAL_ERROR "Test executable does not exist: ${TEST_EXECUTABLE}")
20 COMMAND ${CMAKE_COMMAND} -E env ${TEST_ENV} "${TEST_INTERPRETER}" "${TEST_EXECUTABLE}" --list-tests
21 WORKING_DIRECTORY "${TEST_WORKING_DIR}"
22 OUTPUT_VARIABLE output
23 RESULT_VARIABLE result
25 if(NOT "${result}" EQUAL 0)
26 string(REPLACE "\n" "\n " output "${output}")
29 "Error running test executable: ${TEST_EXECUTABLE}\n"
36 string(REPLACE "\n" ";" tests_list "${output}")
37 foreach(test_name ${tests_list})
40 "${TEST_PREFIX}${test_name}"
41 ${CMAKE_COMMAND} -E env ${TEST_ENV}
42 "${TEST_INTERPRETER}" "${TEST_EXECUTABLE}" "${test_name}"
46 "${TEST_PREFIX}${test_name}"
48 WORKING_DIRECTORY "${TEST_WORKING_DIR}"
53 # Set a list of discovered tests in the parent scope, in case users
54 # want access to this list as a CMake variable
56 add_command(set ${TEST_LIST} ${tests_list})
59 file(WRITE "${CTEST_FILE}" "${ctest_script}")