1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-16 14:08:35 +08:00

ctest: Add support for '--prefix=<prefix>' form of the argument

The main `cmake --preset` argument for configure presets supports both
forms, so support it for `ctest --preset` too.

Fixes: #21855
This commit is contained in:
Brad King
2021-02-23 09:12:55 -05:00
parent 3357d37761
commit 6fa3647023
4 changed files with 21 additions and 6 deletions

View File

@@ -30,7 +30,7 @@ This program will run the tests and report results.
Options
=======
``--preset <preset>``
``--preset <preset>``, ``--preset=<preset>``
Use a test preset to specify test options. The project binary directory
is inferred from the ``configurePreset`` key. The current working directory
must contain CMake preset files.

View File

@@ -2574,7 +2574,10 @@ int cmCTest::Run(std::vector<std::string>& args, std::string* output)
bool listPresets =
find(args.begin(), args.end(), "--list-presets") != args.end();
auto it = find(args.begin(), args.end(), "--preset");
auto it =
std::find_if(args.begin(), args.end(), [](std::string const& arg) -> bool {
return arg == "--preset" || cmHasLiteralPrefix(arg, "--preset=");
});
if (listPresets || it != args.end()) {
std::string errormsg;
bool success;
@@ -2583,7 +2586,10 @@ int cmCTest::Run(std::vector<std::string>& args, std::string* output)
// If listing presets we don't need a presetName
success = this->SetArgsFromPreset("", listPresets);
} else {
if (++it != args.end()) {
if (cmHasLiteralPrefix(*it, "--preset=")) {
auto presetName = it->substr(9);
success = this->SetArgsFromPreset(presetName, listPresets);
} else if (++it != args.end()) {
auto presetName = *it;
success = this->SetArgsFromPreset(presetName, listPresets);
} else {

View File

@@ -26,7 +26,8 @@ static const char* cmDocumentationUsage[][2] = { { nullptr,
{ nullptr, nullptr } };
static const char* cmDocumentationOptions[][2] = {
{ "--preset <preset>", "Read arguments from a test preset." },
{ "--preset <preset>, --preset=<preset>",
"Read arguments from a test preset." },
{ "--list-presets", "List available test presets." },
{ "-C <cfg>, --build-config <cfg>", "Choose configuration to test." },
{ "--progress", "Enable short progress output from tests." },

View File

@@ -51,6 +51,7 @@ function(run_cmake_test_presets name CMakePresetsTest_CONFIGURE_PRESETS CMakePre
endforeach()
endif()
set(eq 0)
foreach(TEST_PRESET ${CMakePresetsTest_TEST_PRESETS})
if (EXISTS "${RunCMake_SOURCE_DIR}/${name}-test-${TEST_PRESET}-check.cmake")
set(RunCMake-check-file "${name}-test-${TEST_PRESET}-check.cmake")
@@ -58,8 +59,15 @@ function(run_cmake_test_presets name CMakePresetsTest_CONFIGURE_PRESETS CMakePre
set(RunCMake-check-file "check.cmake")
endif()
run_cmake_command(${name}-test-${TEST_PRESET}
${CMAKE_CTEST_COMMAND} "--preset" "${TEST_PRESET}" ${ARGN})
if(eq)
run_cmake_command(${name}-test-${TEST_PRESET}
${CMAKE_CTEST_COMMAND} "--preset=${TEST_PRESET}" ${ARGN})
set(eq 0)
else()
run_cmake_command(${name}-test-${TEST_PRESET}
${CMAKE_CTEST_COMMAND} "--preset" "${TEST_PRESET}" ${ARGN})
set(eq 1)
endif()
endforeach()
endfunction()