navid/haze / 0a7dd3733e7f112437824753b751754396783304029099ce5b5bff5c75f10616 / cmake/run_sample_test.cmake
run_sample_test.cmake
← cmake · 1133 bytes · raw · download
if(NOT DEFINED HZ OR NOT DEFINED SOURCE OR NOT DEFINED OUTPUT OR NOT DEFINED EXPECT_FAIL)
message(FATAL_ERROR "HZ, SOURCE, OUTPUT, and EXPECT_FAIL are required")
endif()
get_filename_component(output_dir "${OUTPUT}" DIRECTORY)
file(MAKE_DIRECTORY "${output_dir}")
set(command "${HZ}" -o "${OUTPUT}")
if(RELEASE)
list(APPEND command -release)
endif()
if(EXPECT_FAIL)
execute_process(
COMMAND ${command} "${SOURCE}"
RESULT_VARIABLE result
OUTPUT_VARIABLE output
ERROR_VARIABLE error)
if(result EQUAL 0)
file(REMOVE "${OUTPUT}")
message(FATAL_ERROR "expected ${SOURCE} to fail, but it compiled successfully")
endif()
if(EXISTS "${OUTPUT}")
message(FATAL_ERROR "expected ${SOURCE} to fail without producing an executable")
endif()
else()
list(APPEND command -run "${SOURCE}")
execute_process(
COMMAND ${command}
RESULT_VARIABLE result
OUTPUT_VARIABLE output
ERROR_VARIABLE error)
if(NOT result EQUAL 0)
message(FATAL_ERROR "${SOURCE} failed with exit code ${result}\n${error}")
endif()
endif()