summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/cmListCommand.cxx32
-rw-r--r--Source/cmListCommand.h2
-rw-r--r--Tests/CMakeTests/ListTest.cmake.in14
3 files changed, 28 insertions, 20 deletions
diff --git a/Source/cmListCommand.cxx b/Source/cmListCommand.cxx
index 1a1a9d8..e671b6b 100644
--- a/Source/cmListCommand.cxx
+++ b/Source/cmListCommand.cxx
@@ -38,9 +38,9 @@ bool cmListCommand::InitialPass(std::vector<std::string> const& args)
{
return this->HandleGetCommand(args);
}
- if(subCommand == "SET" || subCommand == "APPEND")
+ if(subCommand == "APPEND")
{
- return this->HandleSetCommand(args);
+ return this->HandleAppendCommand(args);
}
if(subCommand == "INSERT")
{
@@ -72,9 +72,6 @@ bool cmListCommand::GetListString(std::string& listString, const char* var)
= this->Makefile->GetDefinition(var);
if(!cacheValue)
{
- cmOStringStream str;
- str << "cannot find variable: " << var;
- this->SetError(str.str().c_str());
return false;
}
listString = cacheValue;
@@ -133,7 +130,8 @@ bool cmListCommand::HandleGetCommand(std::vector<std::string> const& args)
std::vector<std::string> varArgsExpanded;
if ( !this->GetList(varArgsExpanded, listName.c_str()) )
{
- return false;
+ this->Makefile->AddDefinition(variableName.c_str(), "NOTFOUND");
+ return true;
}
std::string value;
@@ -167,21 +165,18 @@ bool cmListCommand::HandleGetCommand(std::vector<std::string> const& args)
}
//----------------------------------------------------------------------------
-bool cmListCommand::HandleSetCommand(std::vector<std::string> const& args)
+bool cmListCommand::HandleAppendCommand(std::vector<std::string> const& args)
{
if(args.size() < 3)
{
- this->SetError("sub-command SET requires at least two arguments.");
+ this->SetError("sub-command APPEND requires at least two arguments.");
return false;
}
const std::string& listName = args[1];
// expand the variable
std::string listString;
- if ( !this->GetListString(listString, listName.c_str()) )
- {
- return false;
- }
+ this->GetListString(listString, listName.c_str());
size_t cc;
for ( cc = 2; cc < args.size(); ++ cc )
{
@@ -206,15 +201,18 @@ bool cmListCommand::HandleInsertCommand(std::vector<std::string> const& args)
}
const std::string& listName = args[1];
+
// expand the variable
+ int item = atoi(args[2].c_str());
std::vector<std::string> varArgsExpanded;
- if ( !this->GetList(varArgsExpanded, listName.c_str()) )
+ if ( !this->GetList(varArgsExpanded, listName.c_str()) && (item > 0 || item < -1))
{
+ cmOStringStream str;
+ str << "index: " << item << " out of range (-1, 0)";
+ this->SetError(str.str().c_str());
return false;
}
- int item = atoi(args[2].c_str());
-
size_t nitem = varArgsExpanded.size();
if ( item < 0 )
{
@@ -224,8 +222,8 @@ bool cmListCommand::HandleInsertCommand(std::vector<std::string> const& args)
{
cmOStringStream str;
str << "index: " << item << " out of range (-"
- << varArgsExpanded.size() << ", "
- << varArgsExpanded.size()-1 << ")";
+ << varArgsExpanded.size() << ", "
+ << varArgsExpanded.size()-1 << ")";
this->SetError(str.str().c_str());
return false;
}
diff --git a/Source/cmListCommand.h b/Source/cmListCommand.h
index e510d19..779b6bd 100644
--- a/Source/cmListCommand.h
+++ b/Source/cmListCommand.h
@@ -89,7 +89,7 @@ public:
protected:
bool HandleLengthCommand(std::vector<std::string> const& args);
bool HandleGetCommand(std::vector<std::string> const& args);
- bool HandleSetCommand(std::vector<std::string> const& args);
+ bool HandleAppendCommand(std::vector<std::string> const& args);
bool HandleInsertCommand(std::vector<std::string> const& args);
bool HandleRemoveCommand(std::vector<std::string> const& args);
bool HandleRemoveItemCommand(std::vector<std::string> const& args);
diff --git a/Tests/CMakeTests/ListTest.cmake.in b/Tests/CMakeTests/ListTest.cmake.in
index 48b157c..d1e8c2b 100644
--- a/Tests/CMakeTests/ListTest.cmake.in
+++ b/Tests/CMakeTests/ListTest.cmake.in
@@ -13,6 +13,9 @@ TEST("LENGTH mylist result" "4")
LIST(LENGTH "mylist" result)
TEST("LENGTH \"mylist\" result" "4")
+LIST(LENGTH "nonexiting_list1" result)
+TEST("LENGTH \"nonexiting_list1\" result" "0")
+
LIST(GET mylist 3 2 1 0 result)
TEST("GET mylist 3 2 1 0 result" "brad;ken;bill;andy")
@@ -29,9 +32,16 @@ TEST("GET mylist -1 -2 -3 -4 result" "brad;ken;bill;andy")
LIST(GET mylist -1 2 -3 0 result)
TEST("GET mylist -1 2 -3 0 ${result}" "brad;ken;bill;andy")
+LIST(GET "nonexiting_list2" 1 result)
+TEST("GET \"nonexiting_list2\" 1 result" "NOTFOUND")
+
SET(result andy)
-LIST(SET result brad)
-TEST("SET result brad" "andy;brad")
+LIST(APPEND result brad)
+TEST("APPEND result brad" "andy;brad")
+
+LIST(APPEND "nonexiting_list3" brad)
+SET(result "${nonexiting_list3}")
+TEST("APPEND \"nonexiting_list1\" brad" "brad")
SET(result andy brad)
LIST(INSERT result -1 bill ken)