7 message(FATAL_ERROR "${arg} not given!")
11 function(run_cmake test)
12 if(DEFINED ENV{RunCMake_TEST_FILTER} AND NOT test MATCHES "$ENV{RunCMake_TEST_FILTER}")
16 set(top_src "${RunCMake_SOURCE_DIR}")
17 set(top_bin "${RunCMake_BINARY_DIR}")
18 if(EXISTS ${top_src}/${test}-result.txt)
19 file(READ ${top_src}/${test}-result.txt expect_result)
20 string(REGEX REPLACE "\n+$" "" expect_result "${expect_result}")
25 string(TOLOWER ${CMAKE_HOST_SYSTEM_NAME} platform_name)
26 #remove all additional bits from cygwin/msys name
27 if(platform_name MATCHES cygwin)
28 set(platform_name cygwin)
30 if(platform_name MATCHES msys)
31 set(platform_name msys)
35 if(RunCMake-std${o}-file AND EXISTS ${top_src}/${RunCMake-std${o}-file})
36 file(READ ${top_src}/${RunCMake-std${o}-file} expect_std${o})
37 string(REGEX REPLACE "\n+$" "" expect_std${o} "${expect_std${o}}")
38 elseif(EXISTS ${top_src}/${test}-std${o}-${platform_name}.txt)
39 file(READ ${top_src}/${test}-std${o}-${platform_name}.txt expect_std${o})
40 string(REGEX REPLACE "\n+$" "" expect_std${o} "${expect_std${o}}")
41 elseif(EXISTS ${top_src}/${test}-std${o}.txt)
42 file(READ ${top_src}/${test}-std${o}.txt expect_std${o})
43 string(REGEX REPLACE "\n+$" "" expect_std${o} "${expect_std${o}}")
48 if (NOT expect_stderr)
49 if (NOT RunCMake_DEFAULT_stderr)
50 set(RunCMake_DEFAULT_stderr "^$")
52 set(expect_stderr ${RunCMake_DEFAULT_stderr})
55 if (NOT RunCMake_TEST_SOURCE_DIR)
56 set(RunCMake_TEST_SOURCE_DIR "${top_src}")
58 if(NOT RunCMake_TEST_BINARY_DIR)
59 set(RunCMake_TEST_BINARY_DIR "${top_bin}/${test}-build")
61 if(NOT RunCMake_TEST_NO_CLEAN)
62 file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
64 file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
65 if(RunCMake-prep-file AND EXISTS ${top_src}/${RunCMake-prep-file})
66 include(${top_src}/${RunCMake-prep-file})
68 include(${top_src}/${test}-prep.cmake OPTIONAL)
70 if(RunCMake_TEST_OUTPUT_MERGE)
71 set(actual_stderr_var actual_stdout)
74 set(actual_stderr_var actual_stderr)
76 if(DEFINED RunCMake_TEST_TIMEOUT)
77 set(maybe_timeout TIMEOUT ${RunCMake_TEST_TIMEOUT})
81 if(RunCMake-stdin-file AND EXISTS ${top_src}/${RunCMake-stdin-file})
82 set(maybe_input_file INPUT_FILE ${top_src}/${RunCMake-stdin-file})
83 elseif(EXISTS ${top_src}/${test}-stdin.txt)
84 set(maybe_input_file INPUT_FILE ${top_src}/${test}-stdin.txt)
86 set(maybe_input_file "")
88 if(NOT RunCMake_TEST_COMMAND)
89 if(NOT DEFINED RunCMake_TEST_OPTIONS)
90 set(RunCMake_TEST_OPTIONS "")
93 list(APPEND RunCMake_TEST_OPTIONS -DCMAKE_POLICY_DEFAULT_CMP0025=NEW)
95 if(NOT RunCMake_TEST_NO_CMP0129 AND CMAKE_C_COMPILER_ID STREQUAL "LCC")
96 list(APPEND RunCMake_TEST_OPTIONS -DCMAKE_POLICY_DEFAULT_CMP0129=NEW)
98 if(RunCMake_MAKE_PROGRAM)
99 list(APPEND RunCMake_TEST_OPTIONS "-DCMAKE_MAKE_PROGRAM=${RunCMake_MAKE_PROGRAM}")
101 set(RunCMake_TEST_COMMAND ${CMAKE_COMMAND})
102 if(NOT RunCMake_TEST_NO_SOURCE_DIR)
103 list(APPEND RunCMake_TEST_COMMAND "${RunCMake_TEST_SOURCE_DIR}")
105 list(APPEND RunCMake_TEST_COMMAND -G "${RunCMake_GENERATOR}")
106 if(RunCMake_GENERATOR_PLATFORM)
107 list(APPEND RunCMake_TEST_COMMAND -A "${RunCMake_GENERATOR_PLATFORM}")
109 if(RunCMake_GENERATOR_TOOLSET)
110 list(APPEND RunCMake_TEST_COMMAND -T "${RunCMake_GENERATOR_TOOLSET}")
112 if(RunCMake_GENERATOR_INSTANCE)
113 list(APPEND RunCMake_TEST_COMMAND "-DCMAKE_GENERATOR_INSTANCE=${RunCMake_GENERATOR_INSTANCE}")
115 list(APPEND RunCMake_TEST_COMMAND
116 -DRunCMake_TEST=${test}
120 set(RunCMake_TEST_OPTIONS "")
122 if(NOT DEFINED RunCMake_TEST_RAW_ARGS)
123 set(RunCMake_TEST_RAW_ARGS "")
125 if(NOT RunCMake_TEST_COMMAND_WORKING_DIRECTORY)
126 set(RunCMake_TEST_COMMAND_WORKING_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
128 string(CONCAT _code [[execute_process(
129 COMMAND ${RunCMake_TEST_COMMAND}
130 ${RunCMake_TEST_OPTIONS}
131 ]] "${RunCMake_TEST_RAW_ARGS}\n" [[
132 WORKING_DIRECTORY "${RunCMake_TEST_COMMAND_WORKING_DIRECTORY}"
133 OUTPUT_VARIABLE actual_stdout
134 ERROR_VARIABLE ${actual_stderr_var}
135 RESULT_VARIABLE actual_result
140 cmake_language(EVAL CODE "${_code}")
142 if(NOT "${actual_result}" MATCHES "${expect_result}")
143 string(APPEND msg "Result is [${actual_result}], not [${expect_result}].\n")
146 # Special case: remove ninja no-op line from stderr, but not stdout.
147 # Test cases that look for it should use RunCMake_TEST_OUTPUT_MERGE.
148 string(REGEX REPLACE "(^|\r?\n)ninja: no work to do\\.\r?\n" "\\1" actual_stderr "${actual_stderr}")
150 # Remove incidental content from both stdout and stderr.
151 string(CONCAT ignore_line_regex
154 "|[a-z]+\\([0-9]+\\) malloc:"
155 "|clang[^:]*: warning: the object size sanitizer has no effect at -O0, but is explicitly enabled:"
156 "|Error kstat returned"
157 "|Hit xcodebuild bug"
158 "|Recompacting log\\.\\.\\."
161 "|Your license to use PGI[^\n]*expired"
162 "|Please obtain a new version at"
163 "|contact PGI Sales at"
165 "|[^\n]*install_name_tool: warning: changes being made to the file will invalidate the code signature in:"
166 "|[^\n]*xcodebuild[^\n]*DVTPlugInManager"
167 "|[^\n]*xcodebuild[^\n]*Requested but did not find extension point with identifier"
168 "|[^\n]*xcodebuild[^\n]*warning: file type[^\n]*is based on missing file type"
169 "|[^\n]*objc[^\n]*: Class [^\n]* One of the two will be used. Which one is undefined."
170 "|[^\n]*is a member of multiple groups"
171 "|[^\n]*offset in archive not a multiple of 8"
172 "|[^\n]*from Time Machine by path"
173 "|[^\n]*Bullseye Testing Technology"
177 string(REGEX REPLACE "\r\n" "\n" actual_std${o} "${actual_std${o}}")
178 string(REGEX REPLACE "${ignore_line_regex}" "\\1" actual_std${o} "${actual_std${o}}")
179 string(REGEX REPLACE "\n+$" "" actual_std${o} "${actual_std${o}}")
181 if(DEFINED expect_std${o})
182 if(NOT "${actual_std${o}}" MATCHES "${expect_std${o}}")
183 string(REGEX REPLACE "\n" "\n expect-${o}> " expect_${o}
184 " expect-${o}> ${expect_std${o}}")
185 set(expect_${o} "Expected std${o} to match:\n${expect_${o}}\n")
186 string(APPEND msg "std${o} does not match that expected.\n")
190 unset(RunCMake_TEST_FAILED)
191 if(RunCMake-check-file AND EXISTS ${top_src}/${RunCMake-check-file})
192 include(${top_src}/${RunCMake-check-file})
194 include(${top_src}/${test}-check.cmake OPTIONAL)
196 if(RunCMake_TEST_FAILED)
197 set(msg "${RunCMake_TEST_FAILED}\n${msg}")
200 string(REPLACE ";" "\" \"" command "\"${RunCMake_TEST_COMMAND}\"")
201 if(RunCMake_TEST_OPTIONS)
202 string(REPLACE ";" "\" \"" options "\"${RunCMake_TEST_OPTIONS}\"")
203 string(APPEND command " ${options}")
205 if(RunCMake_TEST_RAW_ARGS)
206 string(APPEND command " ${RunCMake_TEST_RAW_ARGS}")
208 string(APPEND msg "Command was:\n command> ${command}\n")
211 string(REGEX REPLACE "\n" "\n actual-out> " actual_out " actual-out> ${actual_stdout}")
212 string(REGEX REPLACE "\n" "\n actual-err> " actual_err " actual-err> ${actual_stderr}")
213 message(SEND_ERROR "${test}${RunCMake_TEST_VARIANT_DESCRIPTION} - FAILED:\n"
216 "Actual stdout:\n${actual_out}\n"
218 "Actual stderr:\n${actual_err}\n"
221 message(STATUS "${test}${RunCMake_TEST_VARIANT_DESCRIPTION} - PASSED")
225 function(run_cmake_command test)
226 set(RunCMake_TEST_COMMAND "${ARGN}")
230 function(run_cmake_script test)
231 set(RunCMake_TEST_COMMAND ${CMAKE_COMMAND} ${ARGN} -P ${RunCMake_SOURCE_DIR}/${test}.cmake)
235 function(run_cmake_with_options test)
236 set(RunCMake_TEST_OPTIONS "${ARGN}")
240 function(run_cmake_with_raw_args test args)
241 set(RunCMake_TEST_RAW_ARGS "${args}")
245 function(ensure_files_match expected_file actual_file)
246 if(NOT EXISTS "${expected_file}")
247 message(FATAL_ERROR "Expected file does not exist:\n ${expected_file}")
249 if(NOT EXISTS "${actual_file}")
250 message(FATAL_ERROR "Actual file does not exist:\n ${actual_file}")
252 file(READ "${expected_file}" expected_file_content)
253 file(READ "${actual_file}" actual_file_content)
254 if(NOT "${expected_file_content}" STREQUAL "${actual_file_content}")
255 message(FATAL_ERROR "Actual file content does not match expected:\n
257 expected file: ${expected_file}\n
259 ${expected_file_content}\n
261 actual file: ${actual_file}\n
263 ${actual_file_content}\n
268 # Protect RunCMake tests from calling environment.
269 unset(ENV{MAKEFLAGS})