GoogleTest: Allow alias target in test discovery

Fixes: #24427
Fixes: #24428
This commit is contained in:
Daniel Pfeifer
2026-03-28 12:03:10 +01:00
committed by Brad King
parent 09d3ee5104
commit 741233a02b
3 changed files with 8 additions and 25 deletions

View File

@@ -599,30 +599,12 @@ function(gtest_discover_tests target)
set(arg_DISCOVERY_MODE ${CMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE})
endif()
get_property(
has_counter
TARGET ${target}
PROPERTY CTEST_DISCOVERED_TEST_COUNTER
SET
)
if(has_counter)
get_property(
counter
TARGET ${target}
PROPERTY CTEST_DISCOVERED_TEST_COUNTER
)
math(EXPR counter "${counter} + 1")
else()
set(counter 1)
endif()
set_property(
TARGET ${target}
PROPERTY CTEST_DISCOVERED_TEST_COUNTER
${counter}
)
string(SHA256 argn_hash "${ARGN}")
string(SUBSTRING "${argn_hash}" 0 8 argn_hash)
string(MAKE_C_IDENTIFIER "${target}_${argn_hash}" ctest_file_base)
# Define rule to generate test list for aforementioned test executable
set(ctest_file_base "${CMAKE_CURRENT_BINARY_DIR}/${target}[${counter}]")
set(ctest_file_base "${CMAKE_CURRENT_BINARY_DIR}/${ctest_file_base}")
set(ctest_include_file "${ctest_file_base}_include.cmake")
set(ctest_tests_file "${ctest_file_base}_tests.cmake")
get_property(test_launcher

View File

@@ -15,9 +15,9 @@ endif()
# uncovered by checking the name buffer flushing above.
# PRE_TEST can have a config-specific tests file, POST_BUILD never does
set(tests_file "@CMAKE_CURRENT_BINARY_DIR@/flush_script_test[1]_tests-Debug.cmake")
set(tests_file "@CMAKE_CURRENT_BINARY_DIR@/flush_script_test_e3b0c442_tests-Debug.cmake")
if(NOT EXISTS "${tests_file}")
set(tests_file "@CMAKE_CURRENT_BINARY_DIR@/flush_script_test[1]_tests.cmake")
set(tests_file "@CMAKE_CURRENT_BINARY_DIR@/flush_script_test_e3b0c442_tests.cmake")
endif()
if(NOT EXISTS "${tests_file}")
message(FATAL_ERROR "Tests file is missing")

View File

@@ -6,10 +6,11 @@ enable_testing()
include(xcode_sign_adhoc.cmake)
add_executable(fake_gtest fake_gtest.cpp)
add_executable(fake::gtest ALIAS fake_gtest)
xcode_sign_adhoc(fake_gtest)
gtest_discover_tests(
fake_gtest
fake::gtest
TEST_PREFIX TEST:
TEST_SUFFIX !1
EXTRA_ARGS how now "\"brown\" cow"