|
|
|
|
|
|
|
set(prefix "${TEST_PREFIX}") |
|
set(suffix "${TEST_SUFFIX}") |
|
set(spec ${TEST_SPEC}) |
|
set(extra_args ${TEST_EXTRA_ARGS}) |
|
set(properties ${TEST_PROPERTIES}) |
|
set(reporter ${TEST_REPORTER}) |
|
set(output_dir ${TEST_OUTPUT_DIR}) |
|
set(output_prefix ${TEST_OUTPUT_PREFIX}) |
|
set(output_suffix ${TEST_OUTPUT_SUFFIX}) |
|
set(script) |
|
set(suite) |
|
set(tests) |
|
|
|
function(add_command NAME) |
|
set(_args "") |
|
|
|
math(EXPR _last_arg ${ARGC}-1) |
|
foreach(_n RANGE 1 ${_last_arg}) |
|
set(_arg "${ARGV${_n}}") |
|
if(_arg MATCHES "[^-./:a-zA-Z0-9_]") |
|
set(_args "${_args} [==[${_arg}]==]") |
|
else() |
|
set(_args "${_args} ${_arg}") |
|
endif() |
|
endforeach() |
|
set(script "${script}${NAME}(${_args})\n" PARENT_SCOPE) |
|
endfunction() |
|
|
|
|
|
if(NOT EXISTS "${TEST_EXECUTABLE}") |
|
message(FATAL_ERROR |
|
"Specified test executable '${TEST_EXECUTABLE}' does not exist" |
|
) |
|
endif() |
|
execute_process( |
|
COMMAND ${TEST_EXECUTOR} "${TEST_EXECUTABLE}" ${spec} --list-test-names-only |
|
OUTPUT_VARIABLE output |
|
RESULT_VARIABLE result |
|
WORKING_DIRECTORY "${TEST_WORKING_DIR}" |
|
) |
|
|
|
if(${result} EQUAL 0) |
|
message(WARNING |
|
"Test executable '${TEST_EXECUTABLE}' contains no tests!\n" |
|
) |
|
elseif(${result} LESS 0) |
|
message(FATAL_ERROR |
|
"Error running test executable '${TEST_EXECUTABLE}':\n" |
|
" Result: ${result}\n" |
|
" Output: ${output}\n" |
|
) |
|
endif() |
|
|
|
string(REPLACE "\n" ";" output "${output}") |
|
|
|
|
|
execute_process( |
|
COMMAND ${TEST_EXECUTOR} "${TEST_EXECUTABLE}" ${spec} --list-reporters |
|
OUTPUT_VARIABLE reporters_output |
|
RESULT_VARIABLE reporters_result |
|
WORKING_DIRECTORY "${TEST_WORKING_DIR}" |
|
) |
|
if(${reporters_result} EQUAL 0) |
|
message(WARNING |
|
"Test executable '${TEST_EXECUTABLE}' contains no reporters!\n" |
|
) |
|
elseif(${reporters_result} LESS 0) |
|
message(FATAL_ERROR |
|
"Error running test executable '${TEST_EXECUTABLE}':\n" |
|
" Result: ${reporters_result}\n" |
|
" Output: ${reporters_output}\n" |
|
) |
|
endif() |
|
string(FIND "${reporters_output}" "${reporter}" reporter_is_valid) |
|
if(reporter AND ${reporter_is_valid} EQUAL -1) |
|
message(FATAL_ERROR |
|
"\"${reporter}\" is not a valid reporter!\n" |
|
) |
|
endif() |
|
|
|
|
|
if(reporter) |
|
set(reporter_arg "--reporter ${reporter}") |
|
endif() |
|
|
|
|
|
if(output_dir AND NOT IS_ABSOLUTE ${output_dir}) |
|
set(output_dir "${TEST_WORKING_DIR}/${output_dir}") |
|
if(NOT EXISTS ${output_dir}) |
|
file(MAKE_DIRECTORY ${output_dir}) |
|
endif() |
|
endif() |
|
|
|
|
|
foreach(line ${output}) |
|
set(test ${line}) |
|
|
|
set(test_name ${test}) |
|
foreach(char , [ ]) |
|
string(REPLACE ${char} "\\${char}" test_name ${test_name}) |
|
endforeach(char) |
|
|
|
if(output_dir) |
|
string(REGEX REPLACE "[^A-Za-z0-9_]" "_" test_name_clean ${test_name}) |
|
set(output_dir_arg "--out ${output_dir}/${output_prefix}${test_name_clean}${output_suffix}") |
|
endif() |
|
|
|
|
|
add_command(add_test |
|
"${prefix}${test}${suffix}" |
|
${TEST_EXECUTOR} |
|
"${TEST_EXECUTABLE}" |
|
"${test_name}" |
|
${extra_args} |
|
"${reporter_arg}" |
|
"${output_dir_arg}" |
|
) |
|
add_command(set_tests_properties |
|
"${prefix}${test}${suffix}" |
|
PROPERTIES |
|
WORKING_DIRECTORY "${TEST_WORKING_DIR}" |
|
${properties} |
|
) |
|
list(APPEND tests "${prefix}${test}${suffix}") |
|
endforeach() |
|
|
|
|
|
|
|
add_command(set ${TEST_LIST} ${tests}) |
|
|
|
|
|
file(WRITE "${CTEST_FILE}" "${script}") |
|
|