diff --git a/cmake/modules/TestSuite.cmake b/cmake/modules/TestSuite.cmake --- a/cmake/modules/TestSuite.cmake +++ b/cmake/modules/TestSuite.cmake @@ -37,41 +37,13 @@ get_target_from_suite(${SUITE} SUITE_TARGET) set(TARGET "${SUITE_TARGET}-${NAME}") - set(COMMAND "$") - set(LOG "${NAME}.log") - set(BASE_RUNNER "${CMAKE_CURRENT_BINARY_DIR}/run-${SUITE}-${NAME}.sh") - set(CONFIG_RUNNER "${CMAKE_CURRENT_BINARY_DIR}/$/run-${SUITE}-${NAME}.sh") - list(JOIN ARGN " " ARGS) - - configure_file( - "${TEST_RUNNER_TEMPLATE}" - "${BASE_RUNNER}" - ) - - # `configure_file()` is not enough as it cannot interpret the generator - # expressions. At the time of writing, the only method to get the target - # location is to use a generator expression (the `LOCATION` property cannot - # be relied upon and is deprecated for non imported targets (see - # https://cmake.org/cmake/help/v3.13/prop_tgt/LOCATION.html), and the only - # method to have a generator expressions interpreted at configure time is to - # use the `file(GENERATE)` method. - # - # `file(GENERATE)` will generate a file for each configuration. - # These file are not allowed to collapse, i.e. they cannot have a different - # content for the same output file. - # Since the executable path can vary with the configuration, the file path - # should be different for each configuration. - file(GENERATE - OUTPUT "${CONFIG_RUNNER}" - INPUT "${BASE_RUNNER}" - ) - add_custom_target(${TARGET} - COMMAND "${CONFIG_RUNNER}" + COMMAND + "${CMAKE_SOURCE_DIR}/cmake/utils/test_wrapper.sh" + "$" "${NAME}.log" ${ARGN} COMMENT "${SUITE}: testing ${NAME}" - DEPENDS - ${EXECUTABLE} - "${CONFIG_RUNNER}" + DEPENDS ${EXECUTABLE} + VERBATIM ) add_dependencies(${SUITE_TARGET} ${TARGET}) endfunction() diff --git a/cmake/templates/TestRunner.cmake.in b/cmake/templates/TestRunner.cmake.in deleted file mode 100755 --- a/cmake/templates/TestRunner.cmake.in +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -"${COMMAND}" ${ARGS} > "${LOG}" 2>&1 || (cat "${LOG}" && exit 1) diff --git a/cmake/utils/test_wrapper.sh b/cmake/utils/test_wrapper.sh new file mode 100755 --- /dev/null +++ b/cmake/utils/test_wrapper.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +export LC_ALL=C.UTF-8 + +# USAGE test_wrapper.sh executable log [args] +# Run the with supplied arguments. +# The stdout and stderr outputs are redirected to the file, which is only +# printed on error. + +EXECUTABLE="$1" +LOG="$2" +shift 2 + +"${EXECUTABLE}" "$@" > "${LOG}" 2>&1 || (cat "${LOG}" && exit 1)