discover_tests: Require properties to be key-value pairs

Issue: #28004
This commit is contained in:
Daniel Pfeifer
2026-07-30 12:21:23 -04:00
committed by Brad King
parent 33a9ce0cd9
commit 6147180017
17 changed files with 74 additions and 0 deletions
+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
)