if(NOT DEFINED APP OR NOT DEFINED EXPECTED_VERSION) message(FATAL_ERROR "APP and EXPECTED_VERSION are required") endif() foreach(mode IN ITEMS default help version invalid extra) set(args) set(expected_exit 0) if(mode STREQUAL "help") set(args --help) elseif(mode STREQUAL "version") set(args --version) elseif(mode STREQUAL "invalid") set(args --record) set(expected_exit 2) elseif(mode STREQUAL "extra") set(args --help --record) set(expected_exit 2) endif() execute_process(COMMAND "${APP}" ${args} RESULT_VARIABLE result OUTPUT_VARIABLE output ERROR_VARIABLE error TIMEOUT 5) if(NOT "${result}" STREQUAL "${expected_exit}") message(FATAL_ERROR "${mode}: exit ${result}, expected ${expected_exit}: ${error}") endif() if(mode STREQUAL "version") if(NOT output STREQUAL "frameyap ${EXPECTED_VERSION}\n") message(FATAL_ERROR "Unexpected version: ${output}") endif() elseif(expected_exit EQUAL 2) if(NOT error MATCHES "Unsupported arguments") message(FATAL_ERROR "Missing rejection diagnostic") endif() elseif(NOT output MATCHES "No device access unless") message(FATAL_ERROR "Missing explicit runtime opt-in status") endif() endforeach()