RunCMakeTest.cmake 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. endfunction()
  55. function(run_GoogleTestXML DISCOVERY_MODE)
  56. # Use a single build tree for a few tests without cleaning.
  57. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTestXML-build)
  58. set(RunCMake_TEST_NO_CLEAN 1)
  59. if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
  60. set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
  61. endif()
  62. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  63. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  64. run_cmake_with_options(GoogleTestXML -DCMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE=${DISCOVERY_MODE})
  65. run_cmake_command(GoogleTestXML-discovery
  66. ${CMAKE_COMMAND}
  67. --build .
  68. --config Debug
  69. --target xml_output
  70. )
  71. run_cmake_command(GoogleTestXML-result
  72. ${CMAKE_CTEST_COMMAND}
  73. -C Debug
  74. -R GoogleTestXML
  75. --no-label-summary
  76. )
  77. endfunction()
  78. function(run_GoogleTest_discovery_timeout DISCOVERY_MODE)
  79. # Use a single build tree for a few tests without cleaning.
  80. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTest-discovery-timeout)
  81. set(RunCMake_TEST_NO_CLEAN 1)
  82. if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
  83. set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
  84. endif()
  85. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  86. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  87. run_cmake_with_options(GoogleTestDiscoveryTimeout -DDISCOVERY_MODE=${DISCOVERY_MODE})
  88. set(RunCMake_TEST_OUTPUT_MERGE 1)
  89. run_cmake_command(GoogleTest-discovery-${DISCOVERY_MODE}-timeout-build
  90. ${CMAKE_COMMAND}
  91. --build .
  92. --config Debug
  93. --target discovery_timeout_test
  94. )
  95. set(RunCMake_TEST_OUTPUT_MERGE 0)
  96. run_cmake_command(GoogleTest-discovery-${DISCOVERY_MODE}-timeout-test
  97. ${CMAKE_CTEST_COMMAND}
  98. -C Debug
  99. -R discovery_timeout_test
  100. --no-label-sumary
  101. )
  102. endfunction()
  103. function(run_GoogleTest_discovery_multi_config)
  104. # Use a single build tree for a few tests without cleaning.
  105. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTest-discovery-multi-config)
  106. set(RunCMake_TEST_NO_CLEAN 1)
  107. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  108. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  109. run_cmake(GoogleTestDiscoveryMultiConfig)
  110. run_cmake_command(GoogleTest-build-release
  111. ${CMAKE_COMMAND}
  112. --build .
  113. --config Release
  114. --target configuration_gtest
  115. )
  116. run_cmake_command(GoogleTest-build-debug
  117. ${CMAKE_COMMAND}
  118. --build .
  119. --config Debug
  120. --target configuration_gtest
  121. )
  122. run_cmake_command(GoogleTest-configuration-release
  123. ${CMAKE_CTEST_COMMAND}
  124. -C Release
  125. -L CONFIG
  126. -N
  127. )
  128. run_cmake_command(GoogleTest-configuration-debug
  129. ${CMAKE_CTEST_COMMAND}
  130. -C Debug
  131. -L CONFIG
  132. -N
  133. )
  134. endfunction()
  135. foreach(DISCOVERY_MODE POST_BUILD PRE_TEST)
  136. message("Testing ${DISCOVERY_MODE} discovery mode via CMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE global override...")
  137. run_GoogleTest(${DISCOVERY_MODE})
  138. run_GoogleTestXML(${DISCOVERY_MODE})
  139. message("Testing ${DISCOVERY_MODE} discovery mode via DISCOVERY_MODE option...")
  140. run_GoogleTest_discovery_timeout(${DISCOVERY_MODE})
  141. endforeach()
  142. if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
  143. message("Testing PRE_TEST discovery multi configuration...")
  144. run_GoogleTest_discovery_multi_config()
  145. endif()