RunCMakeTest.cmake 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. include(RunCMake)
  2. function(run_GoogleTest DISCOVERY_MODE)
  3. # Use a single build tree for a few tests without cleaning.
  4. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTest-build)
  5. set(RunCMake_TEST_NO_CLEAN 1)
  6. if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
  7. set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
  8. endif()
  9. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  10. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  11. run_cmake_with_options(GoogleTest -DCMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE=${DISCOVERY_MODE})
  12. run_cmake_command(GoogleTest-build
  13. ${CMAKE_COMMAND}
  14. --build .
  15. --config Debug
  16. --target fake_gtest
  17. )
  18. run_cmake_command(GoogleTest-property-timeout-exe
  19. ${CMAKE_COMMAND}
  20. --build .
  21. --config Debug
  22. --target property_timeout_test
  23. )
  24. run_cmake_command(GoogleTest-test1
  25. ${CMAKE_CTEST_COMMAND}
  26. -C Debug
  27. -L TEST1
  28. --no-label-summary
  29. )
  30. run_cmake_command(GoogleTest-test2
  31. ${CMAKE_CTEST_COMMAND}
  32. -C Debug
  33. -L TEST2
  34. --no-label-summary
  35. )
  36. run_cmake_command(GoogleTest-test-missing
  37. ${CMAKE_CTEST_COMMAND}
  38. -C Debug
  39. -R no_tests_defined
  40. --no-label-summary
  41. )
  42. run_cmake_command(GoogleTest-property-timeout1
  43. ${CMAKE_CTEST_COMMAND}
  44. -C Debug
  45. -R property_timeout\\.case_no_discovery
  46. --no-label-summary
  47. )
  48. run_cmake_command(GoogleTest-property-timeout2
  49. ${CMAKE_CTEST_COMMAND}
  50. -C Debug
  51. -R property_timeout\\.case_with_discovery
  52. --no-label-summary
  53. )
  54. run_cmake_command(GoogleTest-build
  55. ${CMAKE_COMMAND}
  56. --build .
  57. --config Debug
  58. --target skip_test
  59. )
  60. run_cmake_command(GoogleTest-skip-test
  61. ${CMAKE_CTEST_COMMAND}
  62. -C Debug
  63. -R skip_test
  64. --no-label-summary
  65. )
  66. endfunction()
  67. function(run_GoogleTestXML DISCOVERY_MODE)
  68. # Use a single build tree for a few tests without cleaning.
  69. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTestXML-build)
  70. set(RunCMake_TEST_NO_CLEAN 1)
  71. if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
  72. set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
  73. endif()
  74. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  75. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  76. run_cmake_with_options(GoogleTestXML -DCMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE=${DISCOVERY_MODE})
  77. run_cmake_command(GoogleTestXML-discovery
  78. ${CMAKE_COMMAND}
  79. --build .
  80. --config Debug
  81. --target xml_output
  82. )
  83. run_cmake_command(GoogleTestXML-result
  84. ${CMAKE_CTEST_COMMAND}
  85. -C Debug
  86. -R GoogleTestXML
  87. --no-label-summary
  88. )
  89. endfunction()
  90. function(run_GoogleTest_discovery_timeout DISCOVERY_MODE)
  91. # Use a single build tree for a few tests without cleaning.
  92. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTest-discovery-timeout)
  93. set(RunCMake_TEST_NO_CLEAN 1)
  94. if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
  95. set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
  96. endif()
  97. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  98. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  99. run_cmake_with_options(GoogleTestDiscoveryTimeout -DDISCOVERY_MODE=${DISCOVERY_MODE})
  100. set(RunCMake_TEST_OUTPUT_MERGE 1)
  101. run_cmake_command(GoogleTest-discovery-${DISCOVERY_MODE}-timeout-build
  102. ${CMAKE_COMMAND}
  103. --build .
  104. --config Debug
  105. --target discovery_timeout_test
  106. )
  107. set(RunCMake_TEST_OUTPUT_MERGE 0)
  108. run_cmake_command(GoogleTest-discovery-${DISCOVERY_MODE}-timeout-test
  109. ${CMAKE_CTEST_COMMAND}
  110. -C Debug
  111. -R discovery_timeout_test
  112. --no-label-sumary
  113. )
  114. endfunction()
  115. function(run_GoogleTest_discovery_multi_config)
  116. # Use a single build tree for a few tests without cleaning.
  117. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTest-discovery-multi-config)
  118. set(RunCMake_TEST_NO_CLEAN 1)
  119. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  120. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  121. run_cmake(GoogleTestDiscoveryMultiConfig)
  122. run_cmake_command(GoogleTest-build-release
  123. ${CMAKE_COMMAND}
  124. --build .
  125. --config Release
  126. --target configuration_gtest
  127. )
  128. run_cmake_command(GoogleTest-build-debug
  129. ${CMAKE_COMMAND}
  130. --build .
  131. --config Debug
  132. --target configuration_gtest
  133. )
  134. run_cmake_command(GoogleTest-configuration-release
  135. ${CMAKE_CTEST_COMMAND}
  136. -C Release
  137. -L CONFIG
  138. -N
  139. )
  140. run_cmake_command(GoogleTest-configuration-debug
  141. ${CMAKE_CTEST_COMMAND}
  142. -C Debug
  143. -L CONFIG
  144. -N
  145. )
  146. endfunction()
  147. foreach(DISCOVERY_MODE POST_BUILD PRE_TEST)
  148. message("Testing ${DISCOVERY_MODE} discovery mode via CMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE global override...")
  149. run_GoogleTest(${DISCOVERY_MODE})
  150. run_GoogleTestXML(${DISCOVERY_MODE})
  151. message("Testing ${DISCOVERY_MODE} discovery mode via DISCOVERY_MODE option...")
  152. run_GoogleTest_discovery_timeout(${DISCOVERY_MODE})
  153. endforeach()
  154. if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
  155. message("Testing PRE_TEST discovery multi configuration...")
  156. run_GoogleTest_discovery_multi_config()
  157. endif()