diff options
author | Brad King <brad.king@kitware.com> | 2023-12-07 14:20:29 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2023-12-07 14:20:43 (GMT) |
commit | 256d532593e5f606377b6954456aa8e35533b411 (patch) | |
tree | 7c6bb9eb35f158f1a5fd77f363a186606d3fe4b8 /Tests | |
parent | 7693a8152dd4ad81ef36000e98f09e9de639c0df (diff) | |
parent | 0767016eabf17ab124ae7b454b9ca910dcc17c56 (diff) | |
download | CMake-256d532593e5f606377b6954456aa8e35533b411.zip CMake-256d532593e5f606377b6954456aa8e35533b411.tar.gz CMake-256d532593e5f606377b6954456aa8e35533b411.tar.bz2 |
Merge topic 'GoogleTest-discovery-scope'
0767016eab GoogleTest: Avoid silent failures of dynamic test discovery
Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !9038
Diffstat (limited to 'Tests')
3 files changed, 53 insertions, 0 deletions
diff --git a/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryTestListScoped.cmake b/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryTestListScoped.cmake new file mode 100644 index 0000000..d65fae8 --- /dev/null +++ b/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryTestListScoped.cmake @@ -0,0 +1,13 @@ +enable_language(CXX) + +# 'GoogleTest' module is NOT included here by design to validate that including +# it in a subdirectory will still result in test discovery working correctly if +# 'gtest_discover_tests()' is invoked from a different scope. + +enable_testing() + +include(xcode_sign_adhoc.cmake) + +add_subdirectory(GoogleTestDiscoveryTestListScoped) + +add_gtest_executable(test_list_scoped_test test_list_test.cpp) diff --git a/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryTestListScoped/CMakeLists.txt b/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryTestListScoped/CMakeLists.txt new file mode 100644 index 0000000..762a537 --- /dev/null +++ b/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryTestListScoped/CMakeLists.txt @@ -0,0 +1,13 @@ +# This file mimics one containing GoogleTest-related helper functions. It +# includes the GoogleTest module that (in this test) is NOT included in the +# top-level CMake file. + +include(GoogleTest) + +function(add_gtest_executable TARGET SOURCE) + add_executable(${TARGET} ${SOURCE}) + xcode_sign_adhoc(${TARGET}) + gtest_discover_tests( + ${TARGET} + ) +endfunction() diff --git a/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake b/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake index b494cef..56bbfc9 100644 --- a/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake +++ b/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake @@ -292,6 +292,32 @@ function(run_GoogleTest_discovery_flush_script DISCOVERY_MODE) ) endfunction() +function(run_GoogleTest_discovery_test_list_scoped DISCOVERY_MODE) + # Use a single build tree for a few tests without cleaning. + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTest-discovery-test-list-scoped-build) + set(RunCMake_TEST_NO_CLEAN 1) + if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG) + set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug) + endif() + file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") + file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") + + run_cmake_with_options(GoogleTestDiscoveryTestListScoped -DCMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE=${DISCOVERY_MODE}) + + run_cmake_command(GoogleTest-discovery-test-list-scoped-build + ${CMAKE_COMMAND} + --build . + --config Debug + --target test_list_scoped_test + ) + + run_cmake_command(GoogleTest-discovery-test-list-scoped-test + ${CMAKE_CTEST_COMMAND} + -C Debug + --no-label-summary + ) +endfunction() + foreach(DISCOVERY_MODE POST_BUILD PRE_TEST) message("Testing ${DISCOVERY_MODE} discovery mode via CMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE global override...") run_GoogleTest(${DISCOVERY_MODE}) @@ -303,6 +329,7 @@ foreach(DISCOVERY_MODE POST_BUILD PRE_TEST) run_GoogleTest_discovery_arg_change(${DISCOVERY_MODE}) endif() run_GoogleTest_discovery_test_list(${DISCOVERY_MODE}) + run_GoogleTest_discovery_test_list_scoped(${DISCOVERY_MODE}) run_GoogleTest_discovery_flush_script(${DISCOVERY_MODE}) endforeach() |