From 3b92585cf088d2d316755b77e51a13b4c0173b8b Mon Sep 17 00:00:00 2001 From: Andy Cedilnik Date: Mon, 15 May 2006 09:25:06 -0400 Subject: ENH: Remove some errors, fix append to work on nonexisting lists --- Source/cmListCommand.cxx | 32 +++++++++++++++----------------- Source/cmListCommand.h | 2 +- Tests/CMakeTests/ListTest.cmake.in | 14 ++++++++++++-- 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 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 const& args) std::vector 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 const& args) } //---------------------------------------------------------------------------- -bool cmListCommand::HandleSetCommand(std::vector const& args) +bool cmListCommand::HandleAppendCommand(std::vector 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 const& args) } const std::string& listName = args[1]; + // expand the variable + int item = atoi(args[2].c_str()); std::vector 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 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 const& args); bool HandleGetCommand(std::vector const& args); - bool HandleSetCommand(std::vector const& args); + bool HandleAppendCommand(std::vector const& args); bool HandleInsertCommand(std::vector const& args); bool HandleRemoveCommand(std::vector const& args); bool HandleRemoveItemCommand(std::vector 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) -- cgit v0.12