1# Check both the exit status and the reason for an expected command failure.
4math(EXPR last "${CMAKE_ARGC} - 1")
5foreach(index RANGE 0 ${last})
7 list(APPEND command "${CMAKE_ARGV${index}}")
8 elseif("${CMAKE_ARGV${index}}" STREQUAL "--")
12if(NOT command OR NOT EXPECTED)
13 message(FATAL_ERROR "Expected a diagnostic and a command after --")
15execute_process(COMMAND ${command} RESULT_VARIABLE result
16 OUTPUT_VARIABLE output ERROR_VARIABLE error TIMEOUT 55)
17if(NOT result MATCHES "^[1-9][0-9]*$" OR NOT "${output}${error}" MATCHES "${EXPECTED}")
18 message(FATAL_ERROR "Expected failure /${EXPECTED}/; exit ${result}\n${output}${error}")
20message(STATUS "Observed expected rejection: ${EXPECTED}")