RunCMakeTest.cmake 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. include(RunCMake)
  2. if(RunCMake_GENERATOR STREQUAL "Borland Makefiles" OR
  3. RunCMake_GENERATOR STREQUAL "Watcom WMake")
  4. set(fs_delay 3)
  5. else()
  6. set(fs_delay 1.125)
  7. endif()
  8. function(run_GoogleTest DISCOVERY_MODE)
  9. # Use a single build tree for a few tests without cleaning.
  10. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTest-build)
  11. set(RunCMake_TEST_NO_CLEAN 1)
  12. if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
  13. set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
  14. endif()
  15. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  16. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  17. run_cmake_with_options(GoogleTest -DCMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE=${DISCOVERY_MODE})
  18. run_cmake_command(GoogleTest-build
  19. ${CMAKE_COMMAND}
  20. --build .
  21. --config Debug
  22. --target fake_gtest
  23. )
  24. run_cmake_command(GoogleTest-property-timeout-exe
  25. ${CMAKE_COMMAND}
  26. --build .
  27. --config Debug
  28. --target property_timeout_test
  29. )
  30. run_cmake_command(GoogleTest-test1
  31. ${CMAKE_CTEST_COMMAND}
  32. -C Debug
  33. -L TEST1
  34. --no-label-summary
  35. )
  36. run_cmake_command(GoogleTest-test2
  37. ${CMAKE_CTEST_COMMAND}
  38. -C Debug
  39. -L TEST2
  40. --no-label-summary
  41. )
  42. run_cmake_command(GoogleTest-test3
  43. ${CMAKE_CTEST_COMMAND}
  44. -C Debug
  45. -L TEST3
  46. --no-label-summary
  47. )
  48. run_cmake_command(GoogleTest-test4
  49. ${CMAKE_CTEST_COMMAND}
  50. -C Debug
  51. -L TEST4
  52. --no-label-summary
  53. )
  54. run_cmake_command(GoogleTest-test-missing
  55. ${CMAKE_CTEST_COMMAND}
  56. -C Debug
  57. -R no_tests_defined
  58. --no-label-summary
  59. )
  60. run_cmake_command(GoogleTest-property-timeout1
  61. ${CMAKE_CTEST_COMMAND}
  62. -C Debug
  63. -R property_timeout\\.case_no_discovery
  64. --no-label-summary
  65. )
  66. run_cmake_command(GoogleTest-property-timeout2
  67. ${CMAKE_CTEST_COMMAND}
  68. -C Debug
  69. -R property_timeout\\.case_with_discovery
  70. --no-label-summary
  71. )
  72. run_cmake_command(GoogleTest-build
  73. ${CMAKE_COMMAND}
  74. --build .
  75. --config Debug
  76. --target skip_test
  77. )
  78. run_cmake_command(GoogleTest-skip-test
  79. ${CMAKE_CTEST_COMMAND}
  80. -C Debug
  81. -R skip_test
  82. --no-label-summary
  83. )
  84. endfunction()
  85. function(run_GoogleTestXML DISCOVERY_MODE)
  86. # Use a single build tree for a few tests without cleaning.
  87. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTestXML-build)
  88. set(RunCMake_TEST_NO_CLEAN 1)
  89. if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
  90. set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
  91. endif()
  92. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  93. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  94. run_cmake_with_options(GoogleTestXML -DCMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE=${DISCOVERY_MODE})
  95. run_cmake_command(GoogleTestXML-discovery
  96. ${CMAKE_COMMAND}
  97. --build .
  98. --config Debug
  99. --target xml_output
  100. )
  101. run_cmake_command(GoogleTestXML-result
  102. ${CMAKE_CTEST_COMMAND}
  103. -C Debug
  104. -R GoogleTestXML
  105. --no-label-summary
  106. )
  107. run_cmake_command(GoogleTestXML-special-result
  108. ${CMAKE_CTEST_COMMAND}
  109. -C Debug
  110. -R GoogleTestXMLSpecial
  111. --no-label-summary
  112. )
  113. endfunction()
  114. function(run_GoogleTest_discovery_timeout DISCOVERY_MODE)
  115. # Use a single build tree for a few tests without cleaning.
  116. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTest-discovery-timeout)
  117. set(RunCMake_TEST_NO_CLEAN 1)
  118. if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
  119. set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
  120. endif()
  121. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  122. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  123. run_cmake_with_options(GoogleTestDiscoveryTimeout -DDISCOVERY_MODE=${DISCOVERY_MODE})
  124. set(RunCMake_TEST_OUTPUT_MERGE 1)
  125. run_cmake_command(GoogleTest-discovery-${DISCOVERY_MODE}-timeout-build
  126. ${CMAKE_COMMAND}
  127. --build .
  128. --config Debug
  129. --target discovery_timeout_test
  130. )
  131. set(RunCMake_TEST_OUTPUT_MERGE 0)
  132. run_cmake_command(GoogleTest-discovery-${DISCOVERY_MODE}-timeout-test
  133. ${CMAKE_CTEST_COMMAND}
  134. -C Debug
  135. -R discovery_timeout_test
  136. --no-label-sumary
  137. )
  138. endfunction()
  139. function(run_GoogleTest_discovery_arg_change DISCOVERY_MODE)
  140. # Use a single build tree for a few tests without cleaning.
  141. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTest-discovery-arg-change)
  142. set(RunCMake_TEST_NO_CLEAN 1)
  143. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  144. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  145. run_cmake_with_options(GoogleTestDiscoveryArgChange
  146. -DCMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE=${DISCOVERY_MODE}
  147. -DTEST_FILTER=basic
  148. )
  149. run_cmake_command(GoogleTest-discovery-arg-change-build
  150. ${CMAKE_COMMAND}
  151. --build .
  152. --config Release
  153. --target fake_gtest
  154. )
  155. run_cmake_command(GoogleTest-discovery-arg-change-basic
  156. ${CMAKE_CTEST_COMMAND}
  157. -C Release
  158. -N
  159. )
  160. execute_process(COMMAND ${CMAKE_COMMAND} -E sleep ${fs_delay}) # handle 1s resolution
  161. run_cmake_with_options(GoogleTestDiscoveryArgChange
  162. -DCMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE=${DISCOVERY_MODE}
  163. -DTEST_FILTER=typed
  164. )
  165. run_cmake_command(GoogleTest-discovery-arg-change-build
  166. ${CMAKE_COMMAND}
  167. --build .
  168. --config Release
  169. --target fake_gtest
  170. )
  171. run_cmake_command(GoogleTest-discovery-arg-change-typed
  172. ${CMAKE_CTEST_COMMAND}
  173. -C Release
  174. -N
  175. )
  176. endfunction()
  177. function(run_GoogleTest_discovery_multi_config)
  178. # Use a single build tree for a few tests without cleaning.
  179. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTest-discovery-multi-config)
  180. set(RunCMake_TEST_NO_CLEAN 1)
  181. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  182. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  183. run_cmake(GoogleTestDiscoveryMultiConfig)
  184. run_cmake_command(GoogleTest-build-release
  185. ${CMAKE_COMMAND}
  186. --build .
  187. --config Release
  188. --target configuration_gtest
  189. )
  190. run_cmake_command(GoogleTest-build-debug
  191. ${CMAKE_COMMAND}
  192. --build .
  193. --config Debug
  194. --target configuration_gtest
  195. )
  196. run_cmake_command(GoogleTest-configuration-release
  197. ${CMAKE_CTEST_COMMAND}
  198. -C Release
  199. -L CONFIG
  200. -N
  201. )
  202. run_cmake_command(GoogleTest-configuration-debug
  203. ${CMAKE_CTEST_COMMAND}
  204. -C Debug
  205. -L CONFIG
  206. -N
  207. )
  208. endfunction()
  209. function(run_GoogleTest_discovery_test_list DISCOVERY_MODE)
  210. # Use a single build tree for a few tests without cleaning.
  211. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTest-discovery-test-list-build)
  212. set(RunCMake_TEST_NO_CLEAN 1)
  213. if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
  214. set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
  215. endif()
  216. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  217. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  218. run_cmake_with_options(GoogleTestDiscoveryTestList -DCMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE=${DISCOVERY_MODE})
  219. run_cmake_command(GoogleTest-discovery-test-list-build
  220. ${CMAKE_COMMAND}
  221. --build .
  222. --config Debug
  223. --target test_list_test
  224. )
  225. run_cmake_command(GoogleTest-discovery-test-list-test
  226. ${CMAKE_CTEST_COMMAND}
  227. -C Debug
  228. --no-label-summary
  229. )
  230. endfunction()
  231. function(run_GoogleTest_discovery_flush_script DISCOVERY_MODE)
  232. # Use a single build tree for a few tests without cleaning.
  233. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTest-discovery-flush-script-build)
  234. set(RunCMake_TEST_NO_CLEAN 1)
  235. if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
  236. set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
  237. endif()
  238. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  239. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  240. run_cmake_with_options(GoogleTestDiscoveryFlushScript -DCMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE=${DISCOVERY_MODE})
  241. run_cmake_command(GoogleTest-discovery-flush-script-build
  242. ${CMAKE_COMMAND}
  243. --build .
  244. --config Debug
  245. --target flush_script_test
  246. )
  247. run_cmake_command(GoogleTest-discovery-flush-script-test
  248. ${CMAKE_CTEST_COMMAND}
  249. -C Debug
  250. --no-label-summary
  251. )
  252. endfunction()
  253. foreach(DISCOVERY_MODE POST_BUILD PRE_TEST)
  254. message("Testing ${DISCOVERY_MODE} discovery mode via CMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE global override...")
  255. run_GoogleTest(${DISCOVERY_MODE})
  256. run_GoogleTestXML(${DISCOVERY_MODE})
  257. message("Testing ${DISCOVERY_MODE} discovery mode via DISCOVERY_MODE option...")
  258. run_GoogleTest_discovery_timeout(${DISCOVERY_MODE})
  259. if(# VS 9 does not rebuild if POST_BUILD command changes.
  260. NOT "${DISCOVERY_MODE};${RunCMake_GENERATOR}" MATCHES "^POST_BUILD;Visual Studio 9")
  261. run_GoogleTest_discovery_arg_change(${DISCOVERY_MODE})
  262. endif()
  263. run_GoogleTest_discovery_test_list(${DISCOVERY_MODE})
  264. run_GoogleTest_discovery_flush_script(${DISCOVERY_MODE})
  265. endforeach()
  266. if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
  267. message("Testing PRE_TEST discovery multi configuration...")
  268. run_GoogleTest_discovery_multi_config()
  269. endif()