Changeset View
Changeset View
Standalone View
Standalone View
cmake/modules/TestSuite.cmake
# Allow to easily build test suites | # Allow to easily build test suites | ||||
macro(add_test_environment VARIABLE VALUE) | |||||
set_property(GLOBAL APPEND PROPERTY TEST_ENVIRONMENT "${VARIABLE}=${VALUE}") | |||||
endmacro() | |||||
function(add_test_custom_target TARGET) | |||||
cmake_parse_arguments(ARG "" "" "CUSTOM_TARGET_ARGS;TEST_COMMAND" ${ARGN}) | |||||
get_property(TEST_ENVIRONMENT GLOBAL PROPERTY TEST_ENVIRONMENT) | |||||
add_custom_target(${TARGET} | |||||
${ARG_CUSTOM_TARGET_ARGS} | |||||
COMMAND ${CMAKE_COMMAND} -E env ${TEST_ENVIRONMENT} ${ARG_TEST_COMMAND} | |||||
) | |||||
endfunction() | |||||
# Define a new target property to hold the list of tests associated with a test | # Define a new target property to hold the list of tests associated with a test | ||||
# suite. This property is named UNIT_TESTS to avoid confusion with the directory | # suite. This property is named UNIT_TESTS to avoid confusion with the directory | ||||
# level property TESTS. | # level property TESTS. | ||||
define_property(TARGET | define_property(TARGET | ||||
PROPERTY UNIT_TESTS | PROPERTY UNIT_TESTS | ||||
BRIEF_DOCS "List of tests" | BRIEF_DOCS "List of tests" | ||||
FULL_DOCS "A list of the tests associated with a test suite" | FULL_DOCS "A list of the tests associated with a test suite" | ||||
) | ) | ||||
Show All 21 Lines | macro(create_test_suite NAME) | ||||
create_test_suite_with_parent_targets(${NAME} check-all check-extended) | create_test_suite_with_parent_targets(${NAME} check-all check-extended) | ||||
endmacro() | endmacro() | ||||
set(TEST_RUNNER_TEMPLATE "${CMAKE_CURRENT_LIST_DIR}/../templates/TestRunner.cmake.in") | set(TEST_RUNNER_TEMPLATE "${CMAKE_CURRENT_LIST_DIR}/../templates/TestRunner.cmake.in") | ||||
function(add_test_runner SUITE NAME EXECUTABLE) | function(add_test_runner SUITE NAME EXECUTABLE) | ||||
get_target_from_suite(${SUITE} SUITE_TARGET) | get_target_from_suite(${SUITE} SUITE_TARGET) | ||||
set(TARGET "${SUITE_TARGET}-${NAME}") | set(TARGET "${SUITE_TARGET}-${NAME}") | ||||
add_custom_target(${TARGET} | add_test_custom_target(${TARGET} | ||||
COMMAND | TEST_COMMAND | ||||
"${CMAKE_SOURCE_DIR}/cmake/utils/test_wrapper.sh" | "${CMAKE_SOURCE_DIR}/cmake/utils/test_wrapper.sh" | ||||
"$<TARGET_FILE:${EXECUTABLE}>" "${NAME}.log" ${ARGN} | "$<TARGET_FILE:${EXECUTABLE}>" "${NAME}.log" ${ARGN} | ||||
CUSTOM_TARGET_ARGS | |||||
COMMENT "${SUITE}: testing ${NAME}" | COMMENT "${SUITE}: testing ${NAME}" | ||||
DEPENDS ${EXECUTABLE} | DEPENDS ${EXECUTABLE} | ||||
VERBATIM | VERBATIM | ||||
) | ) | ||||
add_dependencies(${SUITE_TARGET} ${TARGET}) | add_dependencies(${SUITE_TARGET} ${TARGET}) | ||||
endfunction() | endfunction() | ||||
function(add_test_to_suite SUITE NAME) | function(add_test_to_suite SUITE NAME) | ||||
add_executable(${NAME} EXCLUDE_FROM_ALL ${ARGN}) | add_executable(${NAME} EXCLUDE_FROM_ALL ${ARGN}) | ||||
add_test_runner(${SUITE} ${NAME} ${NAME}) | add_test_runner(${SUITE} ${NAME} ${NAME}) | ||||
▲ Show 20 Lines • Show All 50 Lines • Show Last 20 Lines |