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(RunCMake_MAKE_PROGRAM)
96 list(APPEND RunCMake_TEST_OPTIONS "-DCMAKE_MAKE_PROGRAM=${RunCMake_MAKE_PROGRAM}")
98 set(RunCMake_TEST_COMMAND ${CMAKE_COMMAND})
99 if(NOT RunCMake_TEST_NO_SOURCE_DIR)
100 list(APPEND RunCMake_TEST_COMMAND "${RunCMake_TEST_SOURCE_DIR}")
102 list(APPEND RunCMake_TEST_COMMAND -G "${RunCMake_GENERATOR}")
103 if(RunCMake_GENERATOR_PLATFORM)
104 list(APPEND RunCMake_TEST_COMMAND -A "${RunCMake_GENERATOR_PLATFORM}")
106 if(RunCMake_GENERATOR_TOOLSET)
107 list(APPEND RunCMake_TEST_COMMAND -T "${RunCMake_GENERATOR_TOOLSET}")
109 if(RunCMake_GENERATOR_INSTANCE)
110 list(APPEND RunCMake_TEST_COMMAND "-DCMAKE_GENERATOR_INSTANCE=${RunCMake_GENERATOR_INSTANCE}")
112 list(APPEND RunCMake_TEST_COMMAND
113 -DRunCMake_TEST=${test}
117 set(RunCMake_TEST_OPTIONS "")
119 if(NOT RunCMake_TEST_COMMAND_WORKING_DIRECTORY)
120 set(RunCMake_TEST_COMMAND_WORKING_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
123 COMMAND ${RunCMake_TEST_COMMAND}
124 ${RunCMake_TEST_OPTIONS}
125 WORKING_DIRECTORY "${RunCMake_TEST_COMMAND_WORKING_DIRECTORY}"
126 OUTPUT_VARIABLE actual_stdout
127 ERROR_VARIABLE ${actual_stderr_var}
128 RESULT_VARIABLE actual_result
134 if(NOT "${actual_result}" MATCHES "${expect_result}")
135 string(APPEND msg "Result is [${actual_result}], not [${expect_result}].\n")
138 # Special case: remove ninja no-op line from stderr, but not stdout.
139 # Test cases that look for it should use RunCMake_TEST_OUTPUT_MERGE.
140 string(REGEX REPLACE "(^|\r?\n)ninja: no work to do\\.\r?\n" "\\1" actual_stderr "${actual_stderr}")
142 # Remove incidental content from both stdout and stderr.
143 string(CONCAT ignore_line_regex
146 "|[a-z]+\\([0-9]+\\) malloc:"
147 "|clang[^:]*: warning: the object size sanitizer has no effect at -O0, but is explicitly enabled:"
148 "|Error kstat returned"
149 "|Hit xcodebuild bug"
150 "|Recompacting log\\.\\.\\."
153 "|Your license to use PGI[^\n]*expired"
154 "|Please obtain a new version at"
155 "|contact PGI Sales at"
157 "|[^\n]*install_name_tool: warning: changes being made to the file will invalidate the code signature in:"
158 "|[^\n]*xcodebuild[^\n]*DVTPlugInManager"
159 "|[^\n]*xcodebuild[^\n]*warning: file type[^\n]*is based on missing file type"
160 "|[^\n]*objc[^\n]*: Class [^\n]* One of the two will be used. Which one is undefined."
161 "|[^\n]*is a member of multiple groups"
162 "|[^\n]*offset in archive not a multiple of 8"
163 "|[^\n]*from Time Machine by path"
164 "|[^\n]*Bullseye Testing Technology"
168 string(REGEX REPLACE "\r\n" "\n" actual_std${o} "${actual_std${o}}")
169 string(REGEX REPLACE "${ignore_line_regex}" "\\1" actual_std${o} "${actual_std${o}}")
170 string(REGEX REPLACE "\n+$" "" actual_std${o} "${actual_std${o}}")
172 if(DEFINED expect_std${o})
173 if(NOT "${actual_std${o}}" MATCHES "${expect_std${o}}")
174 string(REGEX REPLACE "\n" "\n expect-${o}> " expect_${o}
175 " expect-${o}> ${expect_std${o}}")
176 set(expect_${o} "Expected std${o} to match:\n${expect_${o}}\n")
177 string(APPEND msg "std${o} does not match that expected.\n")
181 unset(RunCMake_TEST_FAILED)
182 if(RunCMake-check-file AND EXISTS ${top_src}/${RunCMake-check-file})
183 include(${top_src}/${RunCMake-check-file})
185 include(${top_src}/${test}-check.cmake OPTIONAL)
187 if(RunCMake_TEST_FAILED)
188 set(msg "${RunCMake_TEST_FAILED}\n${msg}")
191 string(REPLACE ";" "\" \"" command "\"${RunCMake_TEST_COMMAND}\"")
192 if(RunCMake_TEST_OPTIONS)
193 string(REPLACE ";" "\" \"" options "\"${RunCMake_TEST_OPTIONS}\"")
194 string(APPEND command " ${options}")
196 string(APPEND msg "Command was:\n command> ${command}\n")
199 string(REGEX REPLACE "\n" "\n actual-out> " actual_out " actual-out> ${actual_stdout}")
200 string(REGEX REPLACE "\n" "\n actual-err> " actual_err " actual-err> ${actual_stderr}")
201 message(SEND_ERROR "${test}${RunCMake_TEST_VARIANT_DESCRIPTION} - FAILED:\n"
204 "Actual stdout:\n${actual_out}\n"
206 "Actual stderr:\n${actual_err}\n"
209 message(STATUS "${test}${RunCMake_TEST_VARIANT_DESCRIPTION} - PASSED")
213 function(run_cmake_command test)
214 set(RunCMake_TEST_COMMAND "${ARGN}")
218 function(run_cmake_script test)
219 set(RunCMake_TEST_COMMAND ${CMAKE_COMMAND} ${ARGN} -P ${RunCMake_SOURCE_DIR}/${test}.cmake)
223 function(run_cmake_with_options test)
224 set(RunCMake_TEST_OPTIONS "${ARGN}")
228 function(ensure_files_match expected_file actual_file)
229 if(NOT EXISTS "${expected_file}")
230 message(FATAL_ERROR "Expected file does not exist:\n ${expected_file}")
232 if(NOT EXISTS "${actual_file}")
233 message(FATAL_ERROR "Actual file does not exist:\n ${actual_file}")
235 file(READ "${expected_file}" expected_file_content)
236 file(READ "${actual_file}" actual_file_content)
237 if(NOT "${expected_file_content}" STREQUAL "${actual_file_content}")
238 message(FATAL_ERROR "Actual file content does not match expected:\n
240 expected file: ${expected_file}\n
242 ${expected_file_content}\n
244 actual file: ${actual_file}\n
246 ${actual_file_content}\n
251 # Protect RunCMake tests from calling environment.
252 unset(ENV{MAKEFLAGS})