v0.16.3
Loading...
Searching...
No Matches
ExpectFailure.cmake
Go to the documentation of this file.
1# Check both the exit status and the reason for an expected command failure.
2set(command)
3set(collect FALSE)
4math(EXPR last "${CMAKE_ARGC} - 1")
5foreach(index RANGE 0 ${last})
6 if(collect)
7 list(APPEND command "${CMAKE_ARGV${index}}")
8 elseif("${CMAKE_ARGV${index}}" STREQUAL "--")
9 set(collect TRUE)
10 endif()
11endforeach()
12if(NOT command OR NOT EXPECTED)
13 message(FATAL_ERROR "Expected a diagnostic and a command after --")
14endif()
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}")
19endif()
20message(STATUS "Observed expected rejection: ${EXPECTED}")