9 message(FATAL_ERROR "${arg} not given!")
13 function(run_cmake test)
14 if(DEFINED ENV{RunCMake_TEST_FILTER} AND NOT test MATCHES "$ENV{RunCMake_TEST_FILTER}")
18 set(top_src "${RunCMake_SOURCE_DIR}")
19 set(top_bin "${RunCMake_BINARY_DIR}")
20 if(EXISTS ${top_src}/${test}-result.txt)
21 file(READ ${top_src}/${test}-result.txt expect_result)
22 string(REGEX REPLACE "\n+$" "" expect_result "${expect_result}")
27 string(TOLOWER ${CMAKE_HOST_SYSTEM_NAME} platform_name)
28 #remove all additional bits from cygwin/msys name
29 if(platform_name MATCHES cygwin)
30 set(platform_name cygwin)
32 if(platform_name MATCHES msys)
33 set(platform_name msys)
36 foreach(o IN ITEMS out err)
37 if(RunCMake-std${o}-file AND EXISTS ${top_src}/${RunCMake-std${o}-file})
38 file(READ ${top_src}/${RunCMake-std${o}-file} expect_std${o})
39 string(REGEX REPLACE "\n+$" "" expect_std${o} "${expect_std${o}}")
40 elseif(EXISTS ${top_src}/${test}-std${o}-${platform_name}.txt)
41 file(READ ${top_src}/${test}-std${o}-${platform_name}.txt expect_std${o})
42 string(REGEX REPLACE "\n+$" "" expect_std${o} "${expect_std${o}}")
43 elseif(EXISTS ${top_src}/${test}-std${o}.txt)
44 file(READ ${top_src}/${test}-std${o}.txt expect_std${o})
45 string(REGEX REPLACE "\n+$" "" expect_std${o} "${expect_std${o}}")
50 if (NOT expect_stderr)
51 if (NOT RunCMake_DEFAULT_stderr)
52 set(RunCMake_DEFAULT_stderr "^$")
54 set(expect_stderr ${RunCMake_DEFAULT_stderr})
57 if (NOT RunCMake_TEST_SOURCE_DIR)
58 set(RunCMake_TEST_SOURCE_DIR "${top_src}")
60 if(NOT RunCMake_TEST_BINARY_DIR)
61 set(RunCMake_TEST_BINARY_DIR "${top_bin}/${test}-build")
63 if(NOT RunCMake_TEST_NO_CLEAN)
64 file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
66 file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
67 if(RunCMake-prep-file AND EXISTS ${top_src}/${RunCMake-prep-file})
68 include(${top_src}/${RunCMake-prep-file})
70 include(${top_src}/${test}-prep.cmake OPTIONAL)
72 if(RunCMake_TEST_OUTPUT_MERGE)
73 set(actual_stderr_var actual_stdout)
76 set(actual_stderr_var actual_stderr)
78 if(DEFINED RunCMake_TEST_TIMEOUT)
79 set(maybe_timeout TIMEOUT ${RunCMake_TEST_TIMEOUT})
83 if(RunCMake-stdin-file AND EXISTS ${top_src}/${RunCMake-stdin-file})
84 set(maybe_input_file INPUT_FILE ${top_src}/${RunCMake-stdin-file})
85 elseif(EXISTS ${top_src}/${test}-stdin.txt)
86 set(maybe_input_file INPUT_FILE ${top_src}/${test}-stdin.txt)
88 set(maybe_input_file "")
90 if(NOT RunCMake_TEST_COMMAND)
91 if(NOT DEFINED RunCMake_TEST_OPTIONS)
92 set(RunCMake_TEST_OPTIONS "")
95 list(APPEND RunCMake_TEST_OPTIONS -DCMAKE_POLICY_DEFAULT_CMP0025=NEW)
97 if(NOT RunCMake_TEST_NO_CMP0129 AND CMAKE_C_COMPILER_ID STREQUAL "LCC")
98 list(APPEND RunCMake_TEST_OPTIONS -DCMAKE_POLICY_DEFAULT_CMP0129=NEW)
100 if(RunCMake_MAKE_PROGRAM)
101 list(APPEND RunCMake_TEST_OPTIONS "-DCMAKE_MAKE_PROGRAM=${RunCMake_MAKE_PROGRAM}")
103 set(RunCMake_TEST_COMMAND ${CMAKE_COMMAND})
104 if(NOT RunCMake_TEST_NO_SOURCE_DIR)
105 list(APPEND RunCMake_TEST_COMMAND "${RunCMake_TEST_SOURCE_DIR}")
107 list(APPEND RunCMake_TEST_COMMAND -G "${RunCMake_GENERATOR}")
108 if(RunCMake_GENERATOR_PLATFORM)
109 list(APPEND RunCMake_TEST_COMMAND -A "${RunCMake_GENERATOR_PLATFORM}")
111 if(RunCMake_GENERATOR_TOOLSET)
112 list(APPEND RunCMake_TEST_COMMAND -T "${RunCMake_GENERATOR_TOOLSET}")
114 if(RunCMake_GENERATOR_INSTANCE)
115 list(APPEND RunCMake_TEST_COMMAND "-DCMAKE_GENERATOR_INSTANCE=${RunCMake_GENERATOR_INSTANCE}")
117 list(APPEND RunCMake_TEST_COMMAND
118 -DRunCMake_TEST=${test}
122 set(RunCMake_TEST_OPTIONS "")
124 if(NOT DEFINED RunCMake_TEST_RAW_ARGS)
125 set(RunCMake_TEST_RAW_ARGS "")
127 if(NOT RunCMake_TEST_COMMAND_WORKING_DIRECTORY)
128 set(RunCMake_TEST_COMMAND_WORKING_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
130 string(CONCAT _code [[execute_process(
131 COMMAND ${RunCMake_TEST_COMMAND}
132 ${RunCMake_TEST_OPTIONS}
133 ]] "${RunCMake_TEST_RAW_ARGS}\n" [[
134 WORKING_DIRECTORY "${RunCMake_TEST_COMMAND_WORKING_DIRECTORY}"
135 OUTPUT_VARIABLE actual_stdout
136 ERROR_VARIABLE ${actual_stderr_var}
137 RESULT_VARIABLE actual_result
142 cmake_language(EVAL CODE "${_code}")
144 if(NOT "${actual_result}" MATCHES "${expect_result}")
145 string(APPEND msg "Result is [${actual_result}], not [${expect_result}].\n")
148 # Special case: remove ninja no-op line from stderr, but not stdout.
149 # Test cases that look for it should use RunCMake_TEST_OUTPUT_MERGE.
150 string(REGEX REPLACE "(^|\r?\n)ninja: no work to do\\.\r?\n" "\\1" actual_stderr "${actual_stderr}")
152 # Remove incidental content from both stdout and stderr.
153 string(CONCAT ignore_line_regex
156 "|[a-z]+\\([0-9]+\\) malloc:"
157 "|clang[^:]*: warning: the object size sanitizer has no effect at -O0, but is explicitly enabled:"
158 "|lld-link: warning: procedure symbol record for .* refers to PDB item index [0-9A-Fa-fx]+ which is not a valid function ID record"
159 "|Error kstat returned"
160 "|Hit xcodebuild bug"
161 "|Recompacting log\\.\\.\\."
164 "|Your license to use PGI[^\n]*expired"
165 "|Please obtain a new version at"
166 "|contact PGI Sales at"
167 "|icp?c: remark #10441: The Intel\\(R\\) C\\+\\+ Compiler Classic \\(ICC\\) is deprecated"
169 "|[^\n]*install_name_tool: warning: changes being made to the file will invalidate the code signature in:"
170 "|[^\n]*xcodebuild[^\n]*DVTPlugInManager"
171 "|[^\n]*xcodebuild[^\n]*DVTSDK: Warning: SDK path collision for path"
172 "|[^\n]*xcodebuild[^\n]*Requested but did not find extension point with identifier"
173 "|[^\n]*xcodebuild[^\n]*nil host used in call to allows.*HTTPSCertificateForHost"
174 "|[^\n]*xcodebuild[^\n]*warning: file type[^\n]*is based on missing file type"
175 "|[^\n]*objc[^\n]*: Class [^\n]* One of the two will be used. Which one is undefined."
176 "|[^\n]*is a member of multiple groups"
177 "|[^\n]*offset in archive not a multiple of 8"
178 "|[^\n]*from Time Machine by path"
179 "|[^\n]*Bullseye Testing Technology"
182 foreach(o IN ITEMS out err)
183 string(REGEX REPLACE "\r\n" "\n" actual_std${o} "${actual_std${o}}")
184 string(REGEX REPLACE "${ignore_line_regex}" "\\1" actual_std${o} "${actual_std${o}}")
185 string(REGEX REPLACE "\n+$" "" actual_std${o} "${actual_std${o}}")
187 if(DEFINED expect_std${o})
188 if(NOT "${actual_std${o}}" MATCHES "${expect_std${o}}")
189 string(REGEX REPLACE "\n" "\n expect-${o}> " expect_${o}
190 " expect-${o}> ${expect_std${o}}")
191 set(expect_${o} "Expected std${o} to match:\n${expect_${o}}\n")
192 string(APPEND msg "std${o} does not match that expected.\n")
196 unset(RunCMake_TEST_FAILED)
197 if(RunCMake-check-file AND EXISTS ${top_src}/${RunCMake-check-file})
198 include(${top_src}/${RunCMake-check-file})
200 include(${top_src}/${test}-check.cmake OPTIONAL)
202 if(RunCMake_TEST_FAILED)
203 set(msg "${RunCMake_TEST_FAILED}\n${msg}")
206 string(REPLACE ";" "\" \"" command "\"${RunCMake_TEST_COMMAND}\"")
207 if(RunCMake_TEST_OPTIONS)
208 string(REPLACE ";" "\" \"" options "\"${RunCMake_TEST_OPTIONS}\"")
209 string(APPEND command " ${options}")
211 if(RunCMake_TEST_RAW_ARGS)
212 string(APPEND command " ${RunCMake_TEST_RAW_ARGS}")
214 string(APPEND msg "Command was:\n command> ${command}\n")
217 string(REGEX REPLACE "\n" "\n actual-out> " actual_out " actual-out> ${actual_stdout}")
218 string(REGEX REPLACE "\n" "\n actual-err> " actual_err " actual-err> ${actual_stderr}")
219 message(SEND_ERROR "${test}${RunCMake_TEST_VARIANT_DESCRIPTION} - FAILED:\n"
222 "Actual stdout:\n${actual_out}\n"
224 "Actual stderr:\n${actual_err}\n"
227 message(STATUS "${test}${RunCMake_TEST_VARIANT_DESCRIPTION} - PASSED")
231 function(run_cmake_command test)
232 set(RunCMake_TEST_COMMAND "${ARGN}")
236 function(run_cmake_script test)
237 set(RunCMake_TEST_COMMAND ${CMAKE_COMMAND} ${ARGN} -P ${RunCMake_SOURCE_DIR}/${test}.cmake)
241 function(run_cmake_with_options test)
242 set(RunCMake_TEST_OPTIONS "${ARGN}")
246 function(run_cmake_with_raw_args test args)
247 set(RunCMake_TEST_RAW_ARGS "${args}")
251 function(ensure_files_match expected_file actual_file)
252 if(NOT EXISTS "${expected_file}")
253 message(FATAL_ERROR "Expected file does not exist:\n ${expected_file}")
255 if(NOT EXISTS "${actual_file}")
256 message(FATAL_ERROR "Actual file does not exist:\n ${actual_file}")
258 file(READ "${expected_file}" expected_file_content)
259 file(READ "${actual_file}" actual_file_content)
260 if(NOT "${expected_file_content}" STREQUAL "${actual_file_content}")
261 message(FATAL_ERROR "Actual file content does not match expected:\n
263 expected file: ${expected_file}\n
265 ${expected_file_content}\n
267 actual file: ${actual_file}\n
269 ${actual_file_content}\n
274 # Protect RunCMake tests from calling environment.
275 unset(ENV{MAKEFLAGS})