You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2011/06/05 07:40:59 UTC
svn commit: r1131853 - in /incubator/mesos/trunk/src: configuration.cpp
tests/test_configuration.cpp
Author: benh
Date: Sun Jun 5 05:40:58 2011
New Revision: 1131853
URL: http://svn.apache.org/viewvc?rev=1131853&view=rev
Log:
Fixed the bug for negative arg values. Simplified the code. Added more tests.
Modified:
incubator/mesos/trunk/src/configuration.cpp
incubator/mesos/trunk/src/tests/test_configuration.cpp
Modified: incubator/mesos/trunk/src/configuration.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/configuration.cpp?rev=1131853&r1=1131852&r2=1131853&view=diff
==============================================================================
--- incubator/mesos/trunk/src/configuration.cpp (original)
+++ incubator/mesos/trunk/src/configuration.cpp Sun Jun 5 05:40:58 2011
@@ -103,12 +103,12 @@ void Configuration::loadCommandLine(int
if (args[i].find("--", 0) == 0) {
// handle --blah=25 and --blah
size_t eq = args[i].find_first_of("=");
- if (eq == string::npos) { // handle no value case
+ if (eq == string::npos) { // handle the no value case
key = args[i].substr(2);
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
val = "1";
set = true;
- } else { // handle value case
+ } else { // handle the value case
key = args[i].substr(2, eq-2);
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
val = args[i].substr(eq+1);
@@ -116,18 +116,19 @@ void Configuration::loadCommandLine(int
}
} else if (args[i].find_first_of("-", 0) == 0) {
// handle -blah 25 and -blah
- if ((i+1 >= args.size()) ||
- (i+1 < args.size() && args[i+1].find_first_of("-", 0) == 0)) {
+ if ((i+1 >= args.size()) || // last arg || next arg is new arg
+ (i+1 < args.size() && args[i+1].find_first_of("-", 0) == 0 &&
+ args[i+1].find_first_of("0123456789.", 1) != 1)) {
key = args[i].substr(1);
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
val = "1";
set = true;
- } else if (i+1 < args.size() && args[i+1].find_first_of("-", 0) != 0) {
+ } else { // not last arg && next arg is a value
key = args[i].substr(1);
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
val = args[i+1];
set = true;
- i++; // we've consumed next parameter as "value"-parameter
+ i++; // we've consumed next parameter as a "value"-parameter
}
}
if (set) {
Modified: incubator/mesos/trunk/src/tests/test_configuration.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/test_configuration.cpp?rev=1131853&r1=1131852&r2=1131853&view=diff
==============================================================================
--- incubator/mesos/trunk/src/tests/test_configuration.cpp (original)
+++ incubator/mesos/trunk/src/tests/test_configuration.cpp Sun Jun 5 05:40:58 2011
@@ -31,7 +31,7 @@ TEST(ConfigurationTest, Environment)
TEST(ConfigurationTest, CommandLine)
{
- const int ARGC = 9;
+ const int ARGC = 10;
char* argv[ARGC];
argv[0] = (char*) "./filename";
argv[1] = (char*) "--test1=text1";
@@ -42,15 +42,17 @@ TEST(ConfigurationTest, CommandLine)
argv[6] = (char*) "-negative";
argv[7] = (char*) "-25";
argv[8] = (char*) "--cAsE=4";
+ argv[9] = (char*) "--space=Long String";
Configuration conf(ARGC, argv, false);
- EXPECT_EQ("text1", conf.getParams()["test1"]);
- EXPECT_EQ("1", conf.getParams()["test2"]);
- EXPECT_EQ("text2", conf.getParams()["test3"]);
- EXPECT_EQ("1", conf.getParams()["test4"]);
- EXPECT_EQ("-25", conf.getParams()["negative"]);
- EXPECT_EQ("4", conf.getParams()["case"]);
+ EXPECT_EQ("text1", conf.getParams()["test1"]);
+ EXPECT_EQ("1", conf.getParams()["test2"]);
+ EXPECT_EQ("text2", conf.getParams()["test3"]);
+ EXPECT_EQ("1", conf.getParams()["test4"]);
+ EXPECT_EQ("-25", conf.getParams()["negative"]);
+ EXPECT_EQ("4", conf.getParams()["case"]);
+ EXPECT_EQ("Long String", conf.getParams()["space"]);
}