mirror of
https://github.com/Kitware/CMake.git
synced 2026-02-26 10:48:38 -06:00
Tests: Add RunCMake helper to run cmake with raw execute_process args
This commit is contained in:
@@ -119,12 +119,16 @@ function(run_cmake test)
|
|||||||
else()
|
else()
|
||||||
set(RunCMake_TEST_OPTIONS "")
|
set(RunCMake_TEST_OPTIONS "")
|
||||||
endif()
|
endif()
|
||||||
|
if(NOT DEFINED RunCMake_TEST_RAW_ARGS)
|
||||||
|
set(RunCMake_TEST_RAW_ARGS "")
|
||||||
|
endif()
|
||||||
if(NOT RunCMake_TEST_COMMAND_WORKING_DIRECTORY)
|
if(NOT RunCMake_TEST_COMMAND_WORKING_DIRECTORY)
|
||||||
set(RunCMake_TEST_COMMAND_WORKING_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
|
set(RunCMake_TEST_COMMAND_WORKING_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
|
||||||
endif()
|
endif()
|
||||||
execute_process(
|
string(CONCAT _code [[execute_process(
|
||||||
COMMAND ${RunCMake_TEST_COMMAND}
|
COMMAND ${RunCMake_TEST_COMMAND}
|
||||||
${RunCMake_TEST_OPTIONS}
|
${RunCMake_TEST_OPTIONS}
|
||||||
|
]] "${RunCMake_TEST_RAW_ARGS}\n" [[
|
||||||
WORKING_DIRECTORY "${RunCMake_TEST_COMMAND_WORKING_DIRECTORY}"
|
WORKING_DIRECTORY "${RunCMake_TEST_COMMAND_WORKING_DIRECTORY}"
|
||||||
OUTPUT_VARIABLE actual_stdout
|
OUTPUT_VARIABLE actual_stdout
|
||||||
ERROR_VARIABLE ${actual_stderr_var}
|
ERROR_VARIABLE ${actual_stderr_var}
|
||||||
@@ -132,7 +136,8 @@ function(run_cmake test)
|
|||||||
ENCODING UTF8
|
ENCODING UTF8
|
||||||
${maybe_timeout}
|
${maybe_timeout}
|
||||||
${maybe_input_file}
|
${maybe_input_file}
|
||||||
)
|
)]])
|
||||||
|
cmake_language(EVAL CODE "${_code}")
|
||||||
set(msg "")
|
set(msg "")
|
||||||
if(NOT "${actual_result}" MATCHES "${expect_result}")
|
if(NOT "${actual_result}" MATCHES "${expect_result}")
|
||||||
string(APPEND msg "Result is [${actual_result}], not [${expect_result}].\n")
|
string(APPEND msg "Result is [${actual_result}], not [${expect_result}].\n")
|
||||||
@@ -196,6 +201,9 @@ function(run_cmake test)
|
|||||||
string(REPLACE ";" "\" \"" options "\"${RunCMake_TEST_OPTIONS}\"")
|
string(REPLACE ";" "\" \"" options "\"${RunCMake_TEST_OPTIONS}\"")
|
||||||
string(APPEND command " ${options}")
|
string(APPEND command " ${options}")
|
||||||
endif()
|
endif()
|
||||||
|
if(RunCMake_TEST_RAW_ARGS)
|
||||||
|
string(APPEND command " ${RunCMake_TEST_RAW_ARGS}")
|
||||||
|
endif()
|
||||||
string(APPEND msg "Command was:\n command> ${command}\n")
|
string(APPEND msg "Command was:\n command> ${command}\n")
|
||||||
endif()
|
endif()
|
||||||
if(msg)
|
if(msg)
|
||||||
@@ -228,6 +236,11 @@ function(run_cmake_with_options test)
|
|||||||
run_cmake(${test})
|
run_cmake(${test})
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
function(run_cmake_with_raw_args test args)
|
||||||
|
set(RunCMake_TEST_RAW_ARGS "${args}")
|
||||||
|
run_cmake(${test})
|
||||||
|
endfunction()
|
||||||
|
|
||||||
function(ensure_files_match expected_file actual_file)
|
function(ensure_files_match expected_file actual_file)
|
||||||
if(NOT EXISTS "${expected_file}")
|
if(NOT EXISTS "${expected_file}")
|
||||||
message(FATAL_ERROR "Expected file does not exist:\n ${expected_file}")
|
message(FATAL_ERROR "Expected file does not exist:\n ${expected_file}")
|
||||||
|
|||||||
Reference in New Issue
Block a user