diff options
author | Asit Dhal <dhal.asitk@gmail.com> | 2021-01-07 06:30:00 (GMT) |
---|---|---|
committer | Asit Dhal <dhal.asitk@gmail.com> | 2021-01-12 07:27:40 (GMT) |
commit | 38e2299fc84aa31ca73bebf1efc9123dbc7bee1a (patch) | |
tree | 00d285e77ec9638cc43f7cbdbed884dad2e2c9e2 | |
parent | 4f5a12be2924ceedc41c2da632e30e332f000f37 (diff) | |
download | CMake-38e2299fc84aa31ca73bebf1efc9123dbc7bee1a.zip CMake-38e2299fc84aa31ca73bebf1efc9123dbc7bee1a.tar.gz CMake-38e2299fc84aa31ca73bebf1efc9123dbc7bee1a.tar.bz2 |
list(REMOVE_ITEM): Make removal of an empty item a no-op.
Fixes: #21663
-rw-r--r-- | Source/cmListCommand.cxx | 7 | ||||
-rw-r--r-- | Tests/CMakeTests/ListTest.cmake.in | 3 | ||||
-rw-r--r-- | Tests/RunCMake/list/REMOVE_ITEM-NoItemArg.cmake | 5 | ||||
-rw-r--r-- | Tests/RunCMake/list/RunCMakeTest.cmake | 1 |
4 files changed, 11 insertions, 5 deletions
diff --git a/Source/cmListCommand.cxx b/Source/cmListCommand.cxx index 53c871b..fdddb45 100644 --- a/Source/cmListCommand.cxx +++ b/Source/cmListCommand.cxx @@ -422,9 +422,10 @@ bool HandleJoinCommand(std::vector<std::string> const& args, bool HandleRemoveItemCommand(std::vector<std::string> const& args, cmExecutionStatus& status) { - if (args.size() < 3) { - status.SetError("sub-command REMOVE_ITEM requires two or more arguments."); - return false; + assert(args.size() >= 2); + + if (args.size() == 2) { + return true; } const std::string& listName = args[1]; diff --git a/Tests/CMakeTests/ListTest.cmake.in b/Tests/CMakeTests/ListTest.cmake.in index 785f41d..76737e5 100644 --- a/Tests/CMakeTests/ListTest.cmake.in +++ b/Tests/CMakeTests/ListTest.cmake.in @@ -142,9 +142,8 @@ set(Find-List-Only-STDERR "three") set(Insert-List-Only-STDERR "at least three") set(Length-List-Only-STDERR "two") set(Remove_At-List-Only-STDERR "at least two") -set(Remove_Item-List-Only-STDERR "two or more") -foreach(cmd IN ITEMS Find Get Insert Length Remove_At Remove_Item) +foreach(cmd IN ITEMS Find Get Insert Length Remove_At) string(TOUPPER ${cmd} cmd_upper) set(${cmd}-List-Only-RESULT 1) set(${cmd}-List-Only-STDERR ".*CMake Error at List-${cmd}-List-Only.cmake:1 \\(list\\):.*list sub-command ${cmd_upper} requires ${${cmd}-List-Only-STDERR} arguments.*") diff --git a/Tests/RunCMake/list/REMOVE_ITEM-NoItemArg.cmake b/Tests/RunCMake/list/REMOVE_ITEM-NoItemArg.cmake new file mode 100644 index 0000000..f69c024 --- /dev/null +++ b/Tests/RunCMake/list/REMOVE_ITEM-NoItemArg.cmake @@ -0,0 +1,5 @@ +set(ls "a" "b" "c") +list(REMOVE_ITEM ls alpha) +if (NOT ls STREQUAL "a;b;c") + message(FATAL_ERROR "list(REMOVE_ITEM) modified for empty item") +endif () diff --git a/Tests/RunCMake/list/RunCMakeTest.cmake b/Tests/RunCMake/list/RunCMakeTest.cmake index b4a91bc..c11891c 100644 --- a/Tests/RunCMake/list/RunCMakeTest.cmake +++ b/Tests/RunCMake/list/RunCMakeTest.cmake @@ -30,6 +30,7 @@ run_cmake(FILTER-NotList) run_cmake(REMOVE_AT-NotList) run_cmake(REMOVE_DUPLICATES-NotList) run_cmake(REMOVE_ITEM-NotList) +run_cmake(REMOVE_ITEM-NoItemArg) run_cmake(REVERSE-NotList) run_cmake(SORT-NotList) |