diff options
author | Brad King <brad.king@kitware.com> | 2024-10-07 13:10:25 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2024-10-07 13:10:44 (GMT) |
commit | 9a14348a2c2816569a1d8f873f2b9e6da37aacc6 (patch) | |
tree | 0834bd87facf6831a24713ad5367aac8471e397e /Tests | |
parent | ae64e85ca9084be72c47bc849921a73cd18d9671 (diff) | |
parent | 2dcba446e27f62a7da1a0a1a692eddb49877853c (diff) | |
download | CMake-9a14348a2c2816569a1d8f873f2b9e6da37aacc6.zip CMake-9a14348a2c2816569a1d8f873f2b9e6da37aacc6.tar.gz CMake-9a14348a2c2816569a1d8f873f2b9e6da37aacc6.tar.bz2 |
Merge topic 'GoogleTest-DISCOVERY_EXTRA_ARGS'
2dcba446e2 GoogleTest: Add DISCOVERY_EXTRA_ARGS to gtest_discover_tests()
f55f9fd5c1 Help: Mention TEST_LIST with gtest_discover_tests() can omit tests
Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !9856
Diffstat (limited to 'Tests')
4 files changed, 70 insertions, 0 deletions
diff --git a/Tests/RunCMake/GoogleTest/GoogleTest-discovery-check-test-list-extra-args.cmake b/Tests/RunCMake/GoogleTest/GoogleTest-discovery-check-test-list-extra-args.cmake new file mode 100644 index 0000000..1a54e0b --- /dev/null +++ b/Tests/RunCMake/GoogleTest/GoogleTest-discovery-check-test-list-extra-args.cmake @@ -0,0 +1,6 @@ +list(LENGTH test_list_extra_args_TESTS LIST_SIZE) +set(EXPECTED_SIZE 4) +if(NOT LIST_SIZE EQUAL ${EXPECTED_SIZE}) + message("TEST_LIST should have ${EXPECTED_SIZE} elements but it has ${LIST_SIZE}") + message("The unexpected list: [${test_list_extra_args_TESTS}]") +endif() diff --git a/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryTestListExtraArgs.cmake b/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryTestListExtraArgs.cmake new file mode 100644 index 0000000..2e4118a --- /dev/null +++ b/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryTestListExtraArgs.cmake @@ -0,0 +1,15 @@ +enable_language(CXX) +include(GoogleTest) + +enable_testing() + +include(xcode_sign_adhoc.cmake) + +add_executable(test_list_extra_args test_list_extra_args.cpp) +xcode_sign_adhoc(test_list_extra_args) +gtest_discover_tests( + test_list_extra_args + DISCOVERY_EXTRA_ARGS "how now" "" "\"brown\" cow" +) +set_property(DIRECTORY APPEND PROPERTY TEST_INCLUDE_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/GoogleTest-discovery-check-test-list-extra-args.cmake) diff --git a/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake b/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake index e1bff64..b3edd68 100644 --- a/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake +++ b/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake @@ -355,6 +355,32 @@ function(run_GoogleTest_discovery_test_list_scoped DISCOVERY_MODE) ) endfunction() +function(run_GoogleTest_discovery_test_list_extra_args 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-extra-args-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(GoogleTestDiscoveryTestListExtraArgs -DCMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE=${DISCOVERY_MODE}) + + run_cmake_command(GoogleTest-discovery-test-list-extra-args-build + ${CMAKE_COMMAND} + --build . + --config Debug + --target test_list_extra_args + ) + + run_cmake_command(GoogleTest-discovery-test-list-extra-args-test + ${CMAKE_CTEST_COMMAND} + -C Debug + --no-label-summary + ) +endfunction() + foreach(DISCOVERY_MODE POST_BUILD PRE_TEST) message(STATUS "Testing ${DISCOVERY_MODE} discovery mode via CMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE global override...") run_GoogleTest(${DISCOVERY_MODE}) @@ -367,6 +393,7 @@ foreach(DISCOVERY_MODE POST_BUILD PRE_TEST) run_GoogleTest_discovery_arg_change(${DISCOVERY_MODE}) run_GoogleTest_discovery_test_list(${DISCOVERY_MODE}) run_GoogleTest_discovery_test_list_scoped(${DISCOVERY_MODE}) + run_GoogleTest_discovery_test_list_extra_args(${DISCOVERY_MODE}) run_GoogleTest_discovery_flush_script(${DISCOVERY_MODE}) endforeach() diff --git a/Tests/RunCMake/GoogleTest/test_list_extra_args.cpp b/Tests/RunCMake/GoogleTest/test_list_extra_args.cpp new file mode 100644 index 0000000..f63ec22 --- /dev/null +++ b/Tests/RunCMake/GoogleTest/test_list_extra_args.cpp @@ -0,0 +1,22 @@ +#include <iostream> +#include <string> + +int main(int argc, char** argv) +{ + // Note: This test doesn't actually depend on Google Test as such; + // it only requires that we produce output in the expected format when + // invoked with --gtest_list_tests. Thus, we fake that here. This allows us + // to test the module without actually needing Google Test. + + // Simple test of DISCOVERY_EXTRA_ARGS + if (argc > 4 && std::string(argv[1]) == "--gtest_list_tests" && + std::string(argv[2]) == "how now" && std::string(argv[3]) == "" && + std::string(argv[4]) == "\"brown\" cow") { + std::cout << "test_list_test/test.\n"; + std::cout << " case/0 # GetParam() = 'one'\n"; + std::cout << " case/1 # GetParam() = 'two'\n"; + std::cout << " case/2 # GetParam() = 'three'\n"; + std::cout << " case/3 # GetParam() = 'four'\n"; + } + return 0; +} |