Files
musrsim/tests/expect_failure.cmake

23 lines
614 B
CMake

if(NOT DEFINED PROGRAM OR NOT DEFINED INPUT OR NOT DEFINED EXPECTED)
message(FATAL_ERROR "PROGRAM, INPUT, and EXPECTED are required")
endif()
execute_process(
COMMAND "${PROGRAM}" "${INPUT}"
RESULT_VARIABLE result
OUTPUT_VARIABLE stdout
ERROR_VARIABLE stderr
)
if("${result}" STREQUAL "0")
message(FATAL_ERROR "Command unexpectedly succeeded:\n${stdout}${stderr}")
endif()
set(output "${stdout}${stderr}")
string(FIND "${output}" "${EXPECTED}" matchPosition)
if(matchPosition EQUAL -1)
message(FATAL_ERROR
"Expected diagnostic not found:\n ${EXPECTED}\nActual output:\n${output}"
)
endif()