RunCMakeTest.cmake 14 KB

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