ctest: Improve errors when no preset is specified

Apply the same logic to both "equals" and non-"equals" forms of the
argument when no preset is specified, and add test cases.
This commit is contained in:
Tyler Yankee
2026-03-19 10:18:22 -04:00
parent 27099b79be
commit f8ae1bbbec
6 changed files with 13 additions and 1 deletions
+6 -1
View File
@@ -1835,7 +1835,12 @@ int cmCTest::Run(std::vector<std::string> const& args)
} else {
if (cmHasLiteralPrefix(*it, "--preset=")) {
auto const& presetName = it->substr(9);
success = this->SetArgsFromPreset(presetName, listPresets);
if (presetName.empty()) {
cmSystemTools::Error("'--preset' requires an argument");
success = false;
} else {
success = this->SetArgsFromPreset(presetName, listPresets);
}
} else if (++it != args.end()) {
auto const& presetName = *it;
success = this->SetArgsFromPreset(presetName, listPresets);
@@ -0,0 +1 @@
1
@@ -0,0 +1 @@
^CMake Error: '--preset' requires an argument$
@@ -0,0 +1 @@
1
@@ -0,0 +1 @@
^CMake Error: '--preset' requires an argument$
@@ -95,6 +95,9 @@ set(CMakePresetsTest_NO_CONFIGURE 1)
set(CMakePresetsTest_FILE "${RunCMake_SOURCE_DIR}/Good.json.in")
run_cmake_test_presets(ListPresets "" "" "x" "--list-presets")
run_cmake_command(PresetsNoArg-test ${CMAKE_CTEST_COMMAND} "--preset")
run_cmake_command(PresetsNoArgEq-test ${CMAKE_CTEST_COMMAND} "--preset=")
set(CMakePresetsTest_FILE "${RunCMake_SOURCE_DIR}/Condition.json.in")
run_cmake_test_presets(ConditionListPresets "" "" "x" "--list-presets")
unset(CMakePresetsTest_NO_CONFIGURE)