RunCMakeTest.cmake 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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-test-missing
  58. ${CMAKE_CTEST_COMMAND}
  59. -C Debug
  60. -R no_tests_defined
  61. --no-label-summary
  62. )
  63. run_cmake_command(GoogleTest-property-timeout1
  64. ${CMAKE_CTEST_COMMAND}
  65. -C Debug
  66. -R property_timeout\\.case_no_discovery
  67. --no-label-summary
  68. )
  69. run_cmake_command(GoogleTest-property-timeout2
  70. ${CMAKE_CTEST_COMMAND}
  71. -C Debug
  72. -R property_timeout\\.case_with_discovery
  73. --no-label-summary
  74. )
  75. run_cmake_command(GoogleTest-build
  76. ${CMAKE_COMMAND}
  77. --build .
  78. --config Debug
  79. --target skip_test
  80. )
  81. run_cmake_command(GoogleTest-skip-test
  82. ${CMAKE_CTEST_COMMAND}
  83. -C Debug
  84. -R skip_test
  85. --no-label-summary
  86. )
  87. endfunction()
  88. function(run_Launcher_CMP0178 DISCOVERY_MODE cmp0178)
  89. if(CMAKE_C_COMPILER_ID STREQUAL "MSVC" AND CMAKE_C_COMPILER_VERSION VERSION_LESS "14.0")
  90. return()
  91. endif()
  92. if(CMAKE_VS_PLATFORM_NAME STREQUAL "ARM64" AND CMAKE_C_COMPILER_ID STREQUAL "MSVC" AND CMAKE_C_COMPILER_VERSION VERSION_LESS "19.36")
  93. return()
  94. endif()
  95. # Use a single build tree for a few tests without cleaning.
  96. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/Launcher-CMP0178-${cmp0178}-build)
  97. if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
  98. set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
  99. endif()
  100. run_cmake_with_options(Launcher-CMP0178-${cmp0178}
  101. -DCMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE=${DISCOVERY_MODE}
  102. )
  103. set(RunCMake_TEST_NO_CLEAN 1)
  104. # do not issue any warnings on stderr that would cause the build to fail
  105. set(RunCMake_TEST_OUTPUT_MERGE 1)
  106. run_cmake_command(Launcher-CMP0178-${cmp0178}-build
  107. ${CMAKE_COMMAND}
  108. --build .
  109. --config Debug
  110. )
  111. unset(RunCMake_TEST_OUTPUT_MERGE)
  112. run_cmake_command(Launcher-CMP0178-${cmp0178}-test
  113. ${CMAKE_CTEST_COMMAND}
  114. -C Debug
  115. -V
  116. --no-label-summary
  117. )
  118. endfunction()
  119. function(run_GoogleTestXML DISCOVERY_MODE)
  120. # Use a single build tree for a few tests without cleaning.
  121. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTestXML-build)
  122. set(RunCMake_TEST_NO_CLEAN 1)
  123. if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
  124. set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
  125. endif()
  126. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  127. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  128. run_cmake_with_options(GoogleTestXML -DCMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE=${DISCOVERY_MODE})
  129. run_cmake_command(GoogleTestXML-discovery
  130. ${CMAKE_COMMAND}
  131. --build .
  132. --config Debug
  133. --target xml_output
  134. )
  135. run_cmake_command(GoogleTestXML-result
  136. ${CMAKE_CTEST_COMMAND}
  137. -C Debug
  138. -R GoogleTestXML
  139. --no-label-summary
  140. )
  141. run_cmake_command(GoogleTestXML-special-result
  142. ${CMAKE_CTEST_COMMAND}
  143. -C Debug
  144. -R GoogleTestXMLSpecial
  145. --no-label-summary
  146. )
  147. endfunction()
  148. function(run_GoogleTest_discovery_timeout DISCOVERY_MODE)
  149. # Use a single build tree for a few tests without cleaning.
  150. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTest-discovery-timeout)
  151. set(RunCMake_TEST_NO_CLEAN 1)
  152. if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
  153. set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
  154. endif()
  155. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  156. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  157. run_cmake_with_options(GoogleTestDiscoveryTimeout -DDISCOVERY_MODE=${DISCOVERY_MODE})
  158. set(RunCMake_TEST_OUTPUT_MERGE 1)
  159. run_cmake_command(GoogleTest-discovery-${DISCOVERY_MODE}-timeout-build
  160. ${CMAKE_COMMAND}
  161. --build .
  162. --config Debug
  163. --target discovery_timeout_test
  164. )
  165. set(RunCMake_TEST_OUTPUT_MERGE 0)
  166. run_cmake_command(GoogleTest-discovery-${DISCOVERY_MODE}-timeout-test
  167. ${CMAKE_CTEST_COMMAND}
  168. -C Debug
  169. -R discovery_timeout_test
  170. --no-label-summary
  171. )
  172. endfunction()
  173. function(run_GoogleTest_discovery_arg_change DISCOVERY_MODE)
  174. # Use a single build tree for a few tests without cleaning.
  175. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTest-discovery-arg-change)
  176. set(RunCMake_TEST_NO_CLEAN 1)
  177. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  178. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  179. run_cmake_with_options(GoogleTestDiscoveryArgChange
  180. -DCMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE=${DISCOVERY_MODE}
  181. -DTEST_FILTER=basic
  182. )
  183. run_cmake_command(GoogleTest-discovery-arg-change-build
  184. ${CMAKE_COMMAND}
  185. --build .
  186. --config Release
  187. --target fake_gtest
  188. )
  189. run_cmake_command(GoogleTest-discovery-arg-change-basic
  190. ${CMAKE_CTEST_COMMAND}
  191. -C Release
  192. -N
  193. )
  194. execute_process(COMMAND ${CMAKE_COMMAND} -E sleep ${fs_delay}) # handle 1s resolution
  195. run_cmake_with_options(GoogleTestDiscoveryArgChange
  196. -DCMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE=${DISCOVERY_MODE}
  197. -DTEST_FILTER=typed
  198. )
  199. run_cmake_command(GoogleTest-discovery-arg-change-build
  200. ${CMAKE_COMMAND}
  201. --build .
  202. --config Release
  203. --target fake_gtest
  204. )
  205. run_cmake_command(GoogleTest-discovery-arg-change-typed
  206. ${CMAKE_CTEST_COMMAND}
  207. -C Release
  208. -N
  209. )
  210. endfunction()
  211. function(run_GoogleTest_discovery_multi_config)
  212. # Use a single build tree for a few tests without cleaning.
  213. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTest-discovery-multi-config)
  214. set(RunCMake_TEST_NO_CLEAN 1)
  215. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  216. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  217. run_cmake(GoogleTestDiscoveryMultiConfig)
  218. run_cmake_command(GoogleTest-build-release
  219. ${CMAKE_COMMAND}
  220. --build .
  221. --config Release
  222. --target configuration_gtest
  223. )
  224. run_cmake_command(GoogleTest-build-debug
  225. ${CMAKE_COMMAND}
  226. --build .
  227. --config Debug
  228. --target configuration_gtest
  229. )
  230. run_cmake_command(GoogleTest-configuration-release
  231. ${CMAKE_CTEST_COMMAND}
  232. -C Release
  233. -L CONFIG
  234. -N
  235. )
  236. run_cmake_command(GoogleTest-configuration-debug
  237. ${CMAKE_CTEST_COMMAND}
  238. -C Debug
  239. -L CONFIG
  240. -N
  241. )
  242. endfunction()
  243. function(run_GoogleTest_discovery_test_list DISCOVERY_MODE)
  244. # Use a single build tree for a few tests without cleaning.
  245. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTest-discovery-test-list-build)
  246. set(RunCMake_TEST_NO_CLEAN 1)
  247. if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
  248. set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
  249. endif()
  250. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  251. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  252. run_cmake_with_options(GoogleTestDiscoveryTestList -DCMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE=${DISCOVERY_MODE})
  253. run_cmake_command(GoogleTest-discovery-test-list-build
  254. ${CMAKE_COMMAND}
  255. --build .
  256. --config Debug
  257. --target test_list_test
  258. )
  259. run_cmake_command(GoogleTest-discovery-test-list-test
  260. ${CMAKE_CTEST_COMMAND}
  261. -C Debug
  262. --no-label-summary
  263. )
  264. endfunction()
  265. function(run_GoogleTest_discovery_flush_script DISCOVERY_MODE)
  266. # Use a single build tree for a few tests without cleaning.
  267. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTest-discovery-flush-script-build)
  268. set(RunCMake_TEST_NO_CLEAN 1)
  269. if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
  270. set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
  271. endif()
  272. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  273. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  274. run_cmake_with_options(GoogleTestDiscoveryFlushScript -DCMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE=${DISCOVERY_MODE})
  275. run_cmake_command(GoogleTest-discovery-flush-script-build
  276. ${CMAKE_COMMAND}
  277. --build .
  278. --config Debug
  279. --target flush_script_test
  280. )
  281. run_cmake_command(GoogleTest-discovery-flush-script-test
  282. ${CMAKE_CTEST_COMMAND}
  283. -C Debug
  284. --no-label-summary
  285. )
  286. endfunction()
  287. function(run_GoogleTest_discovery_test_list_scoped DISCOVERY_MODE)
  288. # Use a single build tree for a few tests without cleaning.
  289. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTest-discovery-test-list-scoped-build)
  290. set(RunCMake_TEST_NO_CLEAN 1)
  291. if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
  292. set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
  293. endif()
  294. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  295. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  296. run_cmake_with_options(GoogleTestDiscoveryTestListScoped -DCMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE=${DISCOVERY_MODE})
  297. run_cmake_command(GoogleTest-discovery-test-list-scoped-build
  298. ${CMAKE_COMMAND}
  299. --build .
  300. --config Debug
  301. --target test_list_scoped_test
  302. )
  303. run_cmake_command(GoogleTest-discovery-test-list-scoped-test
  304. ${CMAKE_CTEST_COMMAND}
  305. -C Debug
  306. --no-label-summary
  307. )
  308. endfunction()
  309. function(run_GoogleTest_discovery_test_list_extra_args DISCOVERY_MODE)
  310. # Use a single build tree for a few tests without cleaning.
  311. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTest-discovery-test-list-extra-args-build)
  312. set(RunCMake_TEST_NO_CLEAN 1)
  313. if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
  314. set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
  315. endif()
  316. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  317. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  318. run_cmake_with_options(GoogleTestDiscoveryTestListExtraArgs -DCMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE=${DISCOVERY_MODE})
  319. run_cmake_command(GoogleTest-discovery-test-list-extra-args-build
  320. ${CMAKE_COMMAND}
  321. --build .
  322. --config Debug
  323. --target test_list_extra_args
  324. )
  325. run_cmake_command(GoogleTest-discovery-test-list-extra-args-test
  326. ${CMAKE_CTEST_COMMAND}
  327. -C Debug
  328. --no-label-summary
  329. )
  330. endfunction()
  331. foreach(DISCOVERY_MODE POST_BUILD PRE_TEST)
  332. message(STATUS "Testing ${DISCOVERY_MODE} discovery mode via CMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE global override...")
  333. run_GoogleTest(${DISCOVERY_MODE})
  334. run_GoogleTestXML(${DISCOVERY_MODE})
  335. run_Launcher_CMP0178(${DISCOVERY_MODE} NEW)
  336. run_Launcher_CMP0178(${DISCOVERY_MODE} OLD)
  337. run_Launcher_CMP0178(${DISCOVERY_MODE} WARN)
  338. message(STATUS "Testing ${DISCOVERY_MODE} discovery mode via DISCOVERY_MODE option...")
  339. run_GoogleTest_discovery_timeout(${DISCOVERY_MODE})
  340. run_GoogleTest_discovery_arg_change(${DISCOVERY_MODE})
  341. run_GoogleTest_discovery_test_list(${DISCOVERY_MODE})
  342. run_GoogleTest_discovery_test_list_scoped(${DISCOVERY_MODE})
  343. run_GoogleTest_discovery_test_list_extra_args(${DISCOVERY_MODE})
  344. run_GoogleTest_discovery_flush_script(${DISCOVERY_MODE})
  345. endforeach()
  346. if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
  347. message(STATUS "Testing PRE_TEST discovery multi configuration...")
  348. run_GoogleTest_discovery_multi_config()
  349. endif()