Merge topic 'list-empty-error'
05604eb
list: Handle errors on empty lists more gracefully (#13138)
This commit is contained in:
commit
c4aa5386fb
|
@ -204,6 +204,12 @@ bool cmListCommand::HandleGetCommand(std::vector<std::string> const& args)
|
||||||
this->Makefile->AddDefinition(variableName.c_str(), "NOTFOUND");
|
this->Makefile->AddDefinition(variableName.c_str(), "NOTFOUND");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
// FIXME: Add policy to make non-existing lists an error like empty lists.
|
||||||
|
if(varArgsExpanded.empty())
|
||||||
|
{
|
||||||
|
this->SetError("GET given empty list");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
std::string value;
|
std::string value;
|
||||||
size_t cc;
|
size_t cc;
|
||||||
|
@ -318,7 +324,8 @@ bool cmListCommand::HandleInsertCommand(std::vector<std::string> const& args)
|
||||||
// expand the variable
|
// expand the variable
|
||||||
int item = atoi(args[2].c_str());
|
int item = atoi(args[2].c_str());
|
||||||
std::vector<std::string> varArgsExpanded;
|
std::vector<std::string> varArgsExpanded;
|
||||||
if ( !this->GetList(varArgsExpanded, listName.c_str()) && item != 0)
|
if((!this->GetList(varArgsExpanded, listName.c_str())
|
||||||
|
|| varArgsExpanded.empty()) && item != 0)
|
||||||
{
|
{
|
||||||
cmOStringStream str;
|
cmOStringStream str;
|
||||||
str << "index: " << item << " out of range (0, 0)";
|
str << "index: " << item << " out of range (0, 0)";
|
||||||
|
@ -544,6 +551,12 @@ bool cmListCommand::HandleRemoveAtCommand(
|
||||||
this->SetError("sub-command REMOVE_AT requires list to be present.");
|
this->SetError("sub-command REMOVE_AT requires list to be present.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// FIXME: Add policy to make non-existing lists an error like empty lists.
|
||||||
|
if(varArgsExpanded.empty())
|
||||||
|
{
|
||||||
|
this->SetError("REMOVE_AT given empty list");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
size_t cc;
|
size_t cc;
|
||||||
std::vector<size_t> removed;
|
std::vector<size_t> removed;
|
||||||
|
|
|
@ -49,3 +49,4 @@ add_RunCMake_test(ObjectLibrary)
|
||||||
|
|
||||||
add_RunCMake_test(build_command)
|
add_RunCMake_test(build_command)
|
||||||
add_RunCMake_test(find_package)
|
add_RunCMake_test(find_package)
|
||||||
|
add_RunCMake_test(list)
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
cmake_minimum_required(VERSION 2.8)
|
||||||
|
project(${RunCMake_TEST} NONE)
|
||||||
|
include(${RunCMake_TEST}.cmake)
|
|
@ -0,0 +1 @@
|
||||||
|
1
|
|
@ -0,0 +1,4 @@
|
||||||
|
CMake Error at EmptyGet0.cmake:2 \(list\):
|
||||||
|
list GET given empty list
|
||||||
|
Call Stack \(most recent call first\):
|
||||||
|
CMakeLists.txt:3 \(include\)$
|
|
@ -0,0 +1,2 @@
|
||||||
|
set(mylist "")
|
||||||
|
list(GET mylist 0 result)
|
|
@ -0,0 +1 @@
|
||||||
|
1
|
|
@ -0,0 +1,4 @@
|
||||||
|
CMake Error at EmptyInsert-1.cmake:2 \(list\):
|
||||||
|
list index: -1 out of range \(0, 0\)
|
||||||
|
Call Stack \(most recent call first\):
|
||||||
|
CMakeLists.txt:3 \(include\)$
|
|
@ -0,0 +1,2 @@
|
||||||
|
set(mylist "")
|
||||||
|
list(INSERT mylist -1 x)
|
|
@ -0,0 +1 @@
|
||||||
|
1
|
|
@ -0,0 +1,4 @@
|
||||||
|
CMake Error at EmptyRemoveAt0.cmake:2 \(list\):
|
||||||
|
list REMOVE_AT given empty list
|
||||||
|
Call Stack \(most recent call first\):
|
||||||
|
CMakeLists.txt:3 \(include\)$
|
|
@ -0,0 +1,2 @@
|
||||||
|
set(mylist "")
|
||||||
|
list(REMOVE_AT mylist 0)
|
|
@ -0,0 +1,5 @@
|
||||||
|
include(RunCMake)
|
||||||
|
|
||||||
|
run_cmake(EmptyGet0)
|
||||||
|
run_cmake(EmptyRemoveAt0)
|
||||||
|
run_cmake(EmptyInsert-1)
|
Loading…
Reference in New Issue