mesos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mp...@apache.org
Subject mesos git commit: Fixed a bug in the `flags::parse` function and added a couple of tests.
Date Tue, 05 Apr 2016 17:55:27 GMT
Repository: mesos
Updated Branches:
  refs/heads/master 9d49885bb -> d7c80c02d


Fixed a bug in the `flags::parse` function and added a couple of tests.

Review: https://reviews.apache.org/r/45726/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/d7c80c02
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/d7c80c02
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/d7c80c02

Branch: refs/heads/master
Commit: d7c80c02d9b782176ea7a00ea0a1d89a1b7dfd4d
Parents: 9d49885
Author: Michael Park <mpark@apache.org>
Authored: Tue Apr 5 10:45:23 2016 -0700
Committer: Michael Park <mpark@apache.org>
Committed: Tue Apr 5 10:45:42 2016 -0700

----------------------------------------------------------------------
 .../stout/include/stout/flags/parse.hpp         |  8 +++---
 .../3rdparty/stout/tests/flags_tests.cpp        | 26 ++++++++++++++++++--
 2 files changed, 29 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/d7c80c02/3rdparty/libprocess/3rdparty/stout/include/stout/flags/parse.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/flags/parse.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/flags/parse.hpp
index 6313b6b..ef365e4 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/flags/parse.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/flags/parse.hpp
@@ -34,10 +34,12 @@ Try<T> parse(const std::string& value)
   T t;
   std::istringstream in(value);
   in >> t;
-  if (!in.good() && !in.eof()) {
-    return Error("Failed to convert into required type");
+
+  if (in && in.eof()) {
+    return t;
   }
-  return t;
+
+  return Error("Failed to convert into required type");
 }
 
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/d7c80c02/3rdparty/libprocess/3rdparty/stout/tests/flags_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/tests/flags_tests.cpp b/3rdparty/libprocess/3rdparty/stout/tests/flags_tests.cpp
index e87bee2..66e16ab 100644
--- a/3rdparty/libprocess/3rdparty/stout/tests/flags_tests.cpp
+++ b/3rdparty/libprocess/3rdparty/stout/tests/flags_tests.cpp
@@ -130,9 +130,16 @@ TEST(FlagsTest, Add)
             "name8",
             "Also set name8");
 
+  Option<string> name9;
+
+  flags.add(&name9,
+            "name9",
+            "Also set name9");
+
   const map<string, Option<string> > values = {
     {"name6", Some("ben folds")},
-    {"no-name7", None()}
+    {"no-name7", None()},
+    {"name9", Some("")}
   };
 
   flags.load(values);
@@ -142,7 +149,10 @@ TEST(FlagsTest, Add)
 
   EXPECT_FALSE(name7);
 
-  ASSERT_TRUE(name8.isNone());
+  EXPECT_NONE(name8);
+
+  ASSERT_SOME(name9);
+  EXPECT_EQ("", name9.get());
 }
 
 
@@ -495,6 +505,18 @@ TEST(FlagsTest, Errors)
 
   EXPECT_EQ("Failed to load non-boolean flag 'name2' "
             "via 'no-name2'", load.error());
+
+  Option<int> name6;
+  flags.add(&name6, "name6", "Also set name6");
+
+  // Now test a non-boolean flag using empty string value.
+  argv[1] = (char*) "--name6=";
+
+  load = flags.load("FLAGSTEST_", argc, argv);
+  EXPECT_ERROR(load);
+
+  EXPECT_EQ("Failed to load flag 'name6': Failed to load value '': "
+            "Failed to convert into required type", load.error());
 }
 
 


Mime
View raw message