瀏覽代碼

Merge topic 'list-command-insert'

a08154d493 list: Allow inserting at the end of a list

Acked-by: Kitware Robot <[email protected]>
Merge-request: !2181
Brad King 7 年之前
父節點
當前提交
9d1bc0a918

+ 2 - 4
Source/cmListCommand.cxx

@@ -289,12 +289,10 @@ bool cmListCommand::HandleInsertCommand(std::vector<std::string> const& args)
     if (item < 0) {
       item = static_cast<int>(nitem) + item;
     }
-    if (item < 0 || nitem <= static_cast<size_t>(item)) {
+    if (item < 0 || nitem < static_cast<size_t>(item)) {
       std::ostringstream str;
       str << "index: " << item << " out of range (-" << varArgsExpanded.size()
-          << ", "
-          << (varArgsExpanded.empty() ? 0 : (varArgsExpanded.size() - 1))
-          << ")";
+          << ", " << varArgsExpanded.size() << ")";
       this->SetError(str.str());
       return false;
     }

+ 4 - 0
Tests/CMakeTests/ListTest.cmake.in

@@ -53,6 +53,10 @@ set(result andy brad)
 list(INSERT result -1 bill ken)
 TEST("INSERT result -1 bill ken" "andy;bill;ken;brad")
 
+set(result andy brad)
+list(INSERT result 2 bill ken)
+TEST("INSERT result 2 bill ken" "andy;brad;bill;ken")
+
 set(result andy bill brad ken bob)
 list(REMOVE_ITEM result bob)
 TEST("REMOVE_ITEM result bob" "andy;bill;brad;ken")

+ 1 - 1
Tests/RunCMake/list/INSERT-InvalidIndex-stderr.txt

@@ -1,4 +1,4 @@
 ^CMake Error at INSERT-InvalidIndex.cmake:2 \(list\):
-  list index: 3 out of range \(-3, 2\)
+  list index: 4 out of range \(-3, 3\)
 Call Stack \(most recent call first\):
   CMakeLists.txt:3 \(include\)$

+ 1 - 1
Tests/RunCMake/list/INSERT-InvalidIndex.cmake

@@ -1,2 +1,2 @@
 set(mylist alpha bravo charlie)
-list(INSERT mylist 3 delta)
+list(INSERT mylist 4 delta)