RunCMakeTest.cmake 15 KB

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