Merge topic 'discover-tests-crash' into release-4.4

1b2f3287f7 GoogleTest: Restore toleration of odd test PROPERTIES count
6147180017 discover_tests: Require properties to be key-value pairs

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !12350
This commit is contained in:
Brad King
2026-07-31 08:52:04 -04:00
committed by Kitware Robot
18 changed files with 82 additions and 0 deletions
+8
View File
@@ -586,6 +586,14 @@ function(gtest_discover_tests target)
endif()
set(arg_DISCOVERY_MODE ${CMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE})
endif()
if(arg_PROPERTIES)
list(LENGTH arg_PROPERTIES _len_PROPERTIES)
math(EXPR _odd_PROPERTIES "${_len_PROPERTIES} % 2")
if(_odd_PROPERTIES)
list(POP_BACK arg_PROPERTIES _back_PROPERTY)
message(AUTHOR_WARNING "PROPERTIES should be key-value pairs. Ignoring unpaired key '${_back_PROPERTY}'.")
endif()
endif()
get_property(test_launcher
TARGET ${target}
+10
View File
@@ -91,6 +91,16 @@ bool cmCTestDiscoverTests(cmTestDiscoveryArgs const& args,
std::vector<std::string>& testList,
cmExecutionStatus& status)
{
if (args.DiscoveryProperties.size() % 2 != 0) {
status.SetError(" DISCOVERY_PROPERTIES must be key-value pairs.");
return false;
}
if (args.TestProperties.size() % 2 != 0) {
status.SetError(" TEST_PROPERTIES must be key-value pairs.");
return false;
}
cmsys::RegularExpression re;
if (!re.compile(AddAnchors(args.DiscoveryMatch))) {
std::string e = "DISCOVERY_MATCH failed to compile regex \"" +
+10
View File
@@ -110,6 +110,16 @@ bool cmDiscoverTestsCommand(std::vector<std::string> const& args,
return false;
}
if (arguments.DiscoveryProperties.size() % 2 != 0) {
status.SetError(" DISCOVERY_PROPERTIES must be key-value pairs.");
return false;
}
if (arguments.TestProperties.size() % 2 != 0) {
status.SetError(" TEST_PROPERTIES must be key-value pairs.");
return false;
}
cmMakefile& mf = status.GetMakefile();
mf.AddTestGenerator(cm::make_unique<DiscoveryGenerator>(std::move(arguments),
mf.GetBacktrace()));
@@ -23,6 +23,11 @@ block()
${CMAKE_CTEST_COMMAND} -C Debug -N -R "ExpandLists.")
endblock()
block()
run_cmake(bad-discovery-properties-cmake)
run_cmake(bad-test-properties-cmake)
endblock()
function(run_case CASE)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${CASE}-build)
run_cmake(${CASE})
@@ -31,6 +36,9 @@ function(run_case CASE)
run_cmake_command(${CASE}-test ${CMAKE_CTEST_COMMAND} -C Debug)
endfunction()
run_case(bad-discovery-properties-ctest)
run_case(bad-test-properties-ctest)
run_case(bad-command)
run_case(bad-regex)
run_case(discovery-failure)
@@ -0,0 +1,2 @@
CMake Error at .* \(discover_tests\):
discover_tests DISCOVERY_PROPERTIES must be key-value pairs.
@@ -0,0 +1,4 @@
enable_language(C)
enable_testing()
include("${CMAKE_SOURCE_DIR}/shared/bad-discovery-properties.cmake")
@@ -0,0 +1,2 @@
CMake Error at .* \(discover_tests\):
discover_tests DISCOVERY_PROPERTIES must be key-value pairs.
@@ -0,0 +1,5 @@
enable_language(C)
enable_testing()
set_property(DIRECTORY APPEND PROPERTY TEST_INCLUDE_FILES
"${CMAKE_SOURCE_DIR}/shared/bad-discovery-properties.cmake")
@@ -0,0 +1,2 @@
CMake Error at .* \(discover_tests\):
discover_tests TEST_PROPERTIES must be key-value pairs.
@@ -0,0 +1,4 @@
enable_language(C)
enable_testing()
include("${CMAKE_SOURCE_DIR}/shared/bad-test-properties.cmake")
@@ -0,0 +1,2 @@
CMake Error at .* \(discover_tests\):
discover_tests TEST_PROPERTIES must be key-value pairs.
@@ -0,0 +1,5 @@
enable_language(C)
enable_testing()
set_property(DIRECTORY APPEND PROPERTY TEST_INCLUDE_FILES
"${CMAKE_SOURCE_DIR}/shared/bad-test-properties.cmake")
@@ -0,0 +1,8 @@
discover_tests(COMMAND fake_discovery
DISCOVERY_ARGS --list
DISCOVERY_MATCH "^([^,]+),([^,]+)$"
DISCOVERY_PROPERTIES
LABELS UNIT AUTO
TEST_NAME "DT.\\1"
TEST_ARGS --run "\\1"
)
@@ -0,0 +1,8 @@
discover_tests(COMMAND fake_discovery
DISCOVERY_ARGS --list
DISCOVERY_MATCH "^([^,]+),([^,]+)$"
TEST_NAME "DT.\\1"
TEST_ARGS --run "\\1"
TEST_PROPERTIES
LABELS UNIT AUTO
)