navid/haze / 48ef02229ff0b40a4849e26fc1a9f371991f791d48bb426ffeb35dad068eb87d / 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()