Debian Codegraph @

Tests/RunCMake/GoogleTest/RunCMakeTest.cmake

raw
1 include(RunCMake)
2
3 # Isolate our ctest runs from external environment.
4 unset(ENV{CTEST_PARALLEL_LEVEL})
5 unset(ENV{CTEST_OUTPUT_ON_FAILURE})
6
7 if(RunCMake_GENERATOR STREQUAL "Borland Makefiles" OR
8 RunCMake_GENERATOR STREQUAL "Watcom WMake")
9 set(fs_delay 3)
10 else()
11 set(fs_delay 1.125)
12 endif()
13
14 function(run_GoogleTest DISCOVERY_MODE)
15 # Use a single build tree for a few tests without cleaning.
16 set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTest-build)
17 set(RunCMake_TEST_NO_CLEAN 1)
18 if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
19 set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
20 endif()
21 file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
22 file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
23
24 run_cmake_with_options(GoogleTest -DCMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE=${DISCOVERY_MODE})
25
26 run_cmake_command(GoogleTest-build
27 ${CMAKE_COMMAND}
28 --build .
29 --config Debug
30 --target fake_gtest
31 )
32
33 run_cmake_command(GoogleTest-property-timeout-exe
34 ${CMAKE_COMMAND}
35 --build .
36 --config Debug
37 --target property_timeout_test
38 )
39
40 run_cmake_command(GoogleTest-test1
41 ${CMAKE_CTEST_COMMAND}
42 -C Debug
43 -L TEST1
44 --no-label-summary
45 )
46
47 run_cmake_command(GoogleTest-test2
48 ${CMAKE_CTEST_COMMAND}
49 -C Debug
50 -L TEST2
51 --no-label-summary
52 )
53
54 run_cmake_command(GoogleTest-test3
55 ${CMAKE_CTEST_COMMAND}
56 -C Debug
57 -L TEST3
58 --no-label-summary
59 )
60
61 run_cmake_command(GoogleTest-test4
62 ${CMAKE_CTEST_COMMAND}
63 -C Debug
64 -L TEST4
65 --no-label-summary
66 )
67
68 run_cmake_command(GoogleTest-test5
69 ${CMAKE_CTEST_COMMAND}
70 -C Debug
71 -L TEST5
72 --no-label-summary
73 )
74
75 run_cmake_command(GoogleTest-test6
76 ${CMAKE_CTEST_COMMAND}
77 -C Debug
78 -L TEST6
79 --no-label-summary
80 )
81
82 run_cmake_command(GoogleTest-test7
83 ${CMAKE_CTEST_COMMAND}
84 -C Debug
85 -L TEST7
86 --no-label-summary
87 )
88
89 run_cmake_command(GoogleTest-test8
90 ${CMAKE_CTEST_COMMAND}
91 -C Debug
92 -L TEST8
93 --no-label-summary
94 )
95
96 run_cmake_command(GoogleTest-test-missing
97 ${CMAKE_CTEST_COMMAND}
98 -C Debug
99 -R no_tests_defined
100 --no-label-summary
101 )
102
103 run_cmake_command(GoogleTest-property-timeout1
104 ${CMAKE_CTEST_COMMAND}
105 -C Debug
106 -R property_timeout\\.case_no_discovery
107 --no-label-summary
108 )
109
110 run_cmake_command(GoogleTest-property-timeout2
111 ${CMAKE_CTEST_COMMAND}
112 -C Debug
113 -R property_timeout\\.case_with_discovery
114 --no-label-summary
115 )
116
117 run_cmake_command(GoogleTest-build
118 ${CMAKE_COMMAND}
119 --build .
120 --config Debug
121 --target skip_test
122 )
123
124 run_cmake_command(GoogleTest-skip-test
125 ${CMAKE_CTEST_COMMAND}
126 -C Debug
127 -R skip_test
128 --no-label-summary
129 )
130 endfunction()
131
132 function(run_Launcher_CMP0178 DISCOVERY_MODE cmp0178)
133 if(CMAKE_C_COMPILER_ID STREQUAL "MSVC" AND CMAKE_C_COMPILER_VERSION VERSION_LESS "14.0")
134 return()
135 endif()
136 if(CMAKE_VS_PLATFORM_NAME STREQUAL "ARM64" AND CMAKE_C_COMPILER_ID STREQUAL "MSVC" AND CMAKE_C_COMPILER_VERSION VERSION_LESS "19.36")
137 return()
138 endif()
139
140 # Use a single build tree for a few tests without cleaning.
141 set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/Launcher-CMP0178-${cmp0178}-build)
142 if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
143 set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
144 endif()
145
146 run_cmake_with_options(Launcher-CMP0178-${cmp0178}
147 -DCMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE=${DISCOVERY_MODE}
148 )
149
150 set(RunCMake_TEST_NO_CLEAN 1)
151
152 # do not issue any warnings on stderr that would cause the build to fail
153 set(RunCMake_TEST_OUTPUT_MERGE 1)
154 run_cmake_command(Launcher-CMP0178-${cmp0178}-build
155 ${CMAKE_COMMAND}
156 --build .
157 --config Debug
158 )
159 unset(RunCMake_TEST_OUTPUT_MERGE)
160
161 run_cmake_command(Launcher-CMP0178-${cmp0178}-test
162 ${CMAKE_CTEST_COMMAND}
163 -C Debug
164 -V
165 --no-label-summary
166 )
167 endfunction()
168
169 function(run_GoogleTestXML DISCOVERY_MODE)
170 # Use a single build tree for a few tests without cleaning.
171 set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTestXML-build)
172 set(RunCMake_TEST_NO_CLEAN 1)
173 if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
174 set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
175 endif()
176 file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
177 file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
178
179 run_cmake_with_options(GoogleTestXML -DCMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE=${DISCOVERY_MODE})
180
181 run_cmake_command(GoogleTestXML-discovery
182 ${CMAKE_COMMAND}
183 --build .
184 --config Debug
185 --target xml_output
186 )
187
188 run_cmake_command(GoogleTestXML-result
189 ${CMAKE_CTEST_COMMAND}
190 -C Debug
191 -R GoogleTestXML
192 --no-label-summary
193 )
194
195 run_cmake_command(GoogleTestXML-special-result
196 ${CMAKE_CTEST_COMMAND}
197 -C Debug
198 -R GoogleTestXMLSpecial
199 --no-label-summary
200 )
201 endfunction()
202
203 function(run_GoogleTest_discovery_timeout DISCOVERY_MODE)
204 # Use a single build tree for a few tests without cleaning.
205 set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTest-discovery-timeout)
206 set(RunCMake_TEST_NO_CLEAN 1)
207 if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
208 set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
209 endif()
210 file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
211 file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
212
213 run_cmake_with_options(GoogleTestDiscoveryTimeout -DDISCOVERY_MODE=${DISCOVERY_MODE})
214
215 set(RunCMake_TEST_OUTPUT_MERGE 1)
216 run_cmake_command(GoogleTest-discovery-${DISCOVERY_MODE}-timeout-build
217 ${CMAKE_COMMAND}
218 --build .
219 --config Debug
220 --target discovery_timeout_test
221 )
222 set(RunCMake_TEST_OUTPUT_MERGE 0)
223
224 run_cmake_command(GoogleTest-discovery-${DISCOVERY_MODE}-timeout-test
225 ${CMAKE_CTEST_COMMAND}
226 -C Debug
227 -R discovery_timeout_test
228 --no-label-summary
229 )
230 endfunction()
231
232 function(run_GoogleTest_discovery_arg_change DISCOVERY_MODE)
233 # Use a single build tree for a few tests without cleaning.
234 set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTest-discovery-arg-change)
235 set(RunCMake_TEST_NO_CLEAN 1)
236 file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
237 file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
238
239 run_cmake_with_options(GoogleTestDiscoveryArgChange
240 -DCMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE=${DISCOVERY_MODE}
241 -DTEST_FILTER=basic
242 )
243 run_cmake_command(GoogleTest-discovery-arg-change-build
244 ${CMAKE_COMMAND}
245 --build .
246 --config Release
247 --target fake_gtest
248 )
249 run_cmake_command(GoogleTest-discovery-arg-change-basic
250 ${CMAKE_CTEST_COMMAND}
251 -C Release
252 -N
253 )
254 execute_process(COMMAND ${CMAKE_COMMAND} -E sleep ${fs_delay}) # handle 1s resolution
255 run_cmake_with_options(GoogleTestDiscoveryArgChange
256 -DCMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE=${DISCOVERY_MODE}
257 -DTEST_FILTER=typed
258 )
259 run_cmake_command(GoogleTest-discovery-arg-change-build
260 ${CMAKE_COMMAND}
261 --build .
262 --config Release
263 --target fake_gtest
264 )
265 run_cmake_command(GoogleTest-discovery-arg-change-typed
266 ${CMAKE_CTEST_COMMAND}
267 -C Release
268 -N
269 )
270 endfunction()
271
272 function(run_GoogleTest_discovery_multi_config)
273 # Use a single build tree for a few tests without cleaning.
274 set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTest-discovery-multi-config)
275 set(RunCMake_TEST_NO_CLEAN 1)
276 file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
277 file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
278
279 run_cmake(GoogleTestDiscoveryMultiConfig)
280
281 run_cmake_command(GoogleTest-build-release
282 ${CMAKE_COMMAND}
283 --build .
284 --config Release
285 --target configuration_gtest
286 )
287 run_cmake_command(GoogleTest-build-debug
288 ${CMAKE_COMMAND}
289 --build .
290 --config Debug
291 --target configuration_gtest
292 )
293 run_cmake_command(GoogleTest-configuration-release
294 ${CMAKE_CTEST_COMMAND}
295 -C Release
296 -L CONFIG
297 -N
298 )
299 run_cmake_command(GoogleTest-configuration-debug
300 ${CMAKE_CTEST_COMMAND}
301 -C Debug
302 -L CONFIG
303 -N
304 )
305
306 endfunction()
307
308 function(run_GoogleTest_discovery_test_list DISCOVERY_MODE)
309 # Use a single build tree for a few tests without cleaning.
310 set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTest-discovery-test-list-build)
311 set(RunCMake_TEST_NO_CLEAN 1)
312 if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
313 set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
314 endif()
315 file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
316 file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
317
318 run_cmake_with_options(GoogleTestDiscoveryTestList -DCMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE=${DISCOVERY_MODE})
319
320 run_cmake_command(GoogleTest-discovery-test-list-build
321 ${CMAKE_COMMAND}
322 --build .
323 --config Debug
324 --target test_list_test
325 )
326
327 run_cmake_command(GoogleTest-discovery-test-list-test
328 ${CMAKE_CTEST_COMMAND}
329 -C Debug
330 --no-label-summary
331 )
332 endfunction()
333
334 function(run_GoogleTest_discovery_flush_script DISCOVERY_MODE)
335 # Use a single build tree for a few tests without cleaning.
336 set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTest-discovery-flush-script-build)
337 set(RunCMake_TEST_NO_CLEAN 1)
338 if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
339 set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
340 endif()
341 file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
342 file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
343
344 run_cmake_with_options(GoogleTestDiscoveryFlushScript -DCMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE=${DISCOVERY_MODE})
345
346 run_cmake_command(GoogleTest-discovery-flush-script-build
347 ${CMAKE_COMMAND}
348 --build .
349 --config Debug
350 --target flush_script_test
351 )
352
353 run_cmake_command(GoogleTest-discovery-flush-script-test
354 ${CMAKE_CTEST_COMMAND}
355 -C Debug
356 --no-label-summary
357 )
358 endfunction()
359
360 function(run_GoogleTest_discovery_test_list_scoped DISCOVERY_MODE)
361 # Use a single build tree for a few tests without cleaning.
362 set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTest-discovery-test-list-scoped-build)
363 set(RunCMake_TEST_NO_CLEAN 1)
364 if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
365 set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
366 endif()
367 file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
368 file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
369
370 run_cmake_with_options(GoogleTestDiscoveryTestListScoped -DCMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE=${DISCOVERY_MODE})
371
372 run_cmake_command(GoogleTest-discovery-test-list-scoped-build
373 ${CMAKE_COMMAND}
374 --build .
375 --config Debug
376 --target test_list_scoped_test
377 )
378
379 run_cmake_command(GoogleTest-discovery-test-list-scoped-test
380 ${CMAKE_CTEST_COMMAND}
381 -C Debug
382 --no-label-summary
383 )
384 endfunction()
385
386 function(run_GoogleTest_discovery_test_list_extra_args DISCOVERY_MODE)
387 # Use a single build tree for a few tests without cleaning.
388 set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTest-discovery-test-list-extra-args-build)
389 set(RunCMake_TEST_NO_CLEAN 1)
390 if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
391 set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
392 endif()
393 file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
394 file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
395
396 run_cmake_with_options(GoogleTestDiscoveryTestListExtraArgs -DCMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE=${DISCOVERY_MODE})
397
398 run_cmake_command(GoogleTest-discovery-test-list-extra-args-build
399 ${CMAKE_COMMAND}
400 --build .
401 --config Debug
402 --target test_list_extra_args
403 )
404
405 run_cmake_command(GoogleTest-discovery-test-list-extra-args-test
406 ${CMAKE_CTEST_COMMAND}
407 -C Debug
408 --no-label-summary
409 )
410 endfunction()
411
412 function(run_GoogleTest_LegacyParser)
413 # Use a single build tree for a few tests without cleaning.
414 set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTestLegacyParser-build)
415 set(RunCMake_TEST_NO_CLEAN 1)
416 if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
417 set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
418 endif()
419 file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
420 file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
421
422 set(ENV{NO_GTEST_JSON_OUTPUT} 1)
423
424 run_cmake(GoogleTestLegacyParser)
425
426 run_cmake_command(GoogleTestLegacyParser-build
427 ${CMAKE_COMMAND}
428 --build .
429 --config Debug
430 --target fake_gtest
431 )
432
433 set(RunCMake-stdout-file GoogleTest-test1-stdout.txt)
434 run_cmake_command(GoogleTestLegacyParser-test
435 ${CMAKE_CTEST_COMMAND}
436 -C Debug
437 --no-label-summary
438 )
439
440 unset(ENV{NO_GTEST_JSON_OUTPUT})
441 endfunction()
442
443 function(run_GoogleTest_DEF_SOURCE_LINE)
444 # Use a single build tree for a few tests without cleaning.
445 set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTest-DEF_SOURCE_LINE-build)
446 set(RunCMake_TEST_NO_CLEAN 1)
447 if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
448 set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
449 endif()
450 file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
451 file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
452
453 run_cmake(GoogleTestDefSourceLine)
454
455 run_cmake_command(GoogleTest-DEF_SOURCE_LINE-build
456 ${CMAKE_COMMAND}
457 --build .
458 --config Debug
459 --target fake_gtest
460 )
461 run_cmake_command(GoogleTest-DEF_SOURCE_LINE
462 ${CMAKE_CTEST_COMMAND}
463 -C Debug
464 -R "^basic\\.case_"
465 --show-only=json-v1
466 )
467 endfunction()
468
469 foreach(DISCOVERY_MODE POST_BUILD PRE_TEST)
470 message(STATUS "Testing ${DISCOVERY_MODE} discovery mode via CMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE global override...")
471 run_GoogleTest(${DISCOVERY_MODE})
472 run_GoogleTestXML(${DISCOVERY_MODE})
473 run_Launcher_CMP0178(${DISCOVERY_MODE} NEW)
474 run_Launcher_CMP0178(${DISCOVERY_MODE} OLD)
475 run_Launcher_CMP0178(${DISCOVERY_MODE} WARN)
476 message(STATUS "Testing ${DISCOVERY_MODE} discovery mode via DISCOVERY_MODE option...")
477 run_GoogleTest_discovery_timeout(${DISCOVERY_MODE})
478 run_GoogleTest_discovery_arg_change(${DISCOVERY_MODE})
479 run_GoogleTest_discovery_test_list(${DISCOVERY_MODE})
480 run_GoogleTest_discovery_test_list_scoped(${DISCOVERY_MODE})
481 run_GoogleTest_discovery_test_list_extra_args(${DISCOVERY_MODE})
482 run_GoogleTest_discovery_flush_script(${DISCOVERY_MODE})
483 endforeach()
484
485 if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
486 message(STATUS "Testing PRE_TEST discovery multi configuration...")
487 run_GoogleTest_discovery_multi_config()
488 endif()
489
490 block(SCOPE_FOR VARIABLES)
491 # Use a single build tree for a few tests without cleaning.
492 set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/WorkDirWithSpaces-build)
493 set(RunCMake_TEST_NO_CLEAN 1)
494 if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
495 set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
496 endif()
497 file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
498 file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
499
500 run_cmake(WorkDirWithSpaces)
501
502 run_cmake_command(WorkDirWithSpaces-build
503 ${CMAKE_COMMAND}
504 --build .
505 --config Debug
506 --target test_workdir
507 )
508
509 run_cmake_command(WorkDirWithSpaces-test
510 ${CMAKE_CTEST_COMMAND}
511 -C Debug
512 --no-label-summary
513 --output-on-failure
514 )
515 endblock()
516
517 run_GoogleTest_LegacyParser()
518 run_GoogleTest_DEF_SOURCE_LINE()