From 1df3287bf6a49d410b81be670218259afc3474d4 Mon Sep 17 00:00:00 2001 From: Marc Chevrier Date: Fri, 9 Jun 2023 11:44:27 +0200 Subject: add_test: Restore support for empty test arguments This was regressed by refactoring in commit e08ba229ee (CMake code rely on cmList class for CMake lists management (part. 1), 2023-04-14, v3.27.0-rc1~174^2). Fix it and add a test case. Fixes: #24986 --- Source/cmTestGenerator.cxx | 3 ++- Tests/RunCMake/add_test/CheckEmptyArgument.cmake | 11 +++++++++++ Tests/RunCMake/add_test/EmptyArgument.cmake | 5 +++++ Tests/RunCMake/add_test/RunCMakeTest.cmake | 8 ++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 Tests/RunCMake/add_test/CheckEmptyArgument.cmake create mode 100644 Tests/RunCMake/add_test/EmptyArgument.cmake diff --git a/Source/cmTestGenerator.cxx b/Source/cmTestGenerator.cxx index c4a2bc2..ca1226a 100644 --- a/Source/cmTestGenerator.cxx +++ b/Source/cmTestGenerator.cxx @@ -152,7 +152,8 @@ void cmTestGenerator::GenerateScriptForConfig(std::ostream& os, this->EvaluateCommandLineArguments(this->Test->GetCommand(), ge, config), // Expand arguments if COMMAND_EXPAND_LISTS is set this->Test->GetCommandExpandLists() ? cmList::ExpandElements::Yes - : cmList::ExpandElements::No + : cmList::ExpandElements::No, + cmList::EmptyElements::Yes }; // Expanding lists on an empty command may have left it empty if (argv.empty()) { diff --git a/Tests/RunCMake/add_test/CheckEmptyArgument.cmake b/Tests/RunCMake/add_test/CheckEmptyArgument.cmake new file mode 100644 index 0000000..9bf7976 --- /dev/null +++ b/Tests/RunCMake/add_test/CheckEmptyArgument.cmake @@ -0,0 +1,11 @@ +if (NOT CMAKE_ARGV4 STREQUAL "A") + message(FATAL_ERROR "wrong parsing of arguments") +endif() + +if (NOT CMAKE_ARGV5 STREQUAL "") + message(FATAL_ERROR "Empty argument was dropped") +endif() + +if (NOT CMAKE_ARGV6 STREQUAL "B") + message(FATAL_ERROR "wrong parsing of arguments") +endif() diff --git a/Tests/RunCMake/add_test/EmptyArgument.cmake b/Tests/RunCMake/add_test/EmptyArgument.cmake new file mode 100644 index 0000000..7d1a740 --- /dev/null +++ b/Tests/RunCMake/add_test/EmptyArgument.cmake @@ -0,0 +1,5 @@ +enable_testing() +add_test( + NAME "EmptyArgument" + COMMAND "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_LIST_DIR}/CheckEmptyArgument.cmake" -- "A" "" "B" +) diff --git a/Tests/RunCMake/add_test/RunCMakeTest.cmake b/Tests/RunCMake/add_test/RunCMakeTest.cmake index bf6cbff..ec6f6dd 100644 --- a/Tests/RunCMake/add_test/RunCMakeTest.cmake +++ b/Tests/RunCMake/add_test/RunCMakeTest.cmake @@ -33,3 +33,11 @@ foreach(case IN LISTS cases) run_case(OLD-${case}) run_case(NEW-${case}) endforeach() + +block() + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/EmptyArgument-build) + run_cmake(EmptyArgument) + # Run ctest on the generated CTestTestfile.cmake. + set(RunCMake_TEST_NO_CLEAN 1) + run_cmake_command(EmptyArgument-ctest ${CMAKE_CTEST_COMMAND} -C Debug) +endblock() -- cgit v0.12