123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- set(prefix "${TEST_PREFIX}")
- set(suffix "${TEST_SUFFIX}")
- set(spec ${TEST_SPEC})
- set(extra_args ${TEST_EXTRA_ARGS})
- set(properties ${TEST_PROPERTIES})
- set(script)
- set(suite)
- set(tests)
- function(add_command NAME)
- set(_args "")
- foreach(_arg ${ARGN})
- 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()
- macro(_add_catch_test_labels LINE)
-
- string(REPLACE "][" "]\\;[" tags ${line})
- add_command(
- set_tests_properties "${prefix}${test}${suffix}"
- PROPERTIES
- LABELS "${tags}"
- )
- endmacro()
- macro(_add_catch_test LINE)
- set(test ${line})
-
- string(REPLACE "," "\\," test_name ${test})
-
- add_command(
- add_test "${prefix}${test}${suffix}"
- ${TEST_EXECUTOR}
- "${TEST_EXECUTABLE}"
- "${test_name}"
- ${extra_args}
- )
- add_command(
- set_tests_properties "${prefix}${test}${suffix}"
- PROPERTIES
- WORKING_DIRECTORY "${TEST_WORKING_DIR}"
- ${properties}
- )
- list(APPEND tests "${prefix}${test}${suffix}")
- endmacro()
- 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-tests
- OUTPUT_VARIABLE output
- RESULT_VARIABLE result
- )
- 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}")
- set(test)
- set(tags_regex "(\\[([^\\[]*)\\])+$")
- foreach(line ${output})
-
- if(${line} MATCHES "^[ \t]+")
-
- string(REGEX REPLACE "^[ \t]+" "" line ${line})
- if(${line} MATCHES "${tags_regex}")
- _add_catch_test_labels(${line})
- else()
- _add_catch_test(${line})
- endif()
- endif()
- endforeach()
- add_command(set ${TEST_LIST} ${tests})
- file(WRITE "${CTEST_FILE}" "${script}")
|