Stout: Improved the readability of some assertions/expectations.

Prefer checking whether a container is empty instead of checking its
size.

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


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

Branch: refs/heads/master
Commit: 628d6609b6eeb90767e5799d0177bfe4828d71aa
Parents: 2e95dcb
Author: Gastón Kleiman <gas...@mesosphere.io>
Authored: Fri Aug 11 17:02:24 2017 -0700
Committer: Greg Mann <gregorywm...@gmail.com>
Committed: Fri Aug 11 17:02:24 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/tests/flags_tests.cpp         | 16 ++++++++--------
 3rdparty/stout/tests/multimap_tests.cpp      |  8 ++++----
 3rdparty/stout/tests/os/filesystem_tests.cpp |  2 +-
 3rdparty/stout/tests/os/process_tests.cpp    |  4 ++--
 3rdparty/stout/tests/os_tests.cpp            |  2 +-
 3rdparty/stout/tests/proc_tests.cpp          |  2 +-
 3rdparty/stout/tests/strings_tests.cpp       | 10 +++++-----
 7 files changed, 22 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/628d6609/3rdparty/stout/tests/flags_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/tests/flags_tests.cpp 
b/3rdparty/stout/tests/flags_tests.cpp
index d78ab55..88c8ee5 100644
--- a/3rdparty/stout/tests/flags_tests.cpp
+++ b/3rdparty/stout/tests/flags_tests.cpp
@@ -241,7 +241,7 @@ TEST_TEMP_DISABLED_ON_WINDOWS(FlagsTest, 
LoadFromEnvironment)
 
   Try<Warnings> load = flags.load("FLAGSTEST_");
   EXPECT_SOME(load);
-  EXPECT_EQ(0u, load->warnings.size());
+  EXPECT_TRUE(load->warnings.empty());
 
   EXPECT_EQ("billy joel", flags.name1);
   EXPECT_EQ(43, flags.name2);
@@ -274,7 +274,7 @@ TEST(FlagsTest, LoadFromCommandLine)
 
   Try<Warnings> load = flags.load("FLAGSTEST_", arraySize(argv), argv);
   EXPECT_SOME(load);
-  EXPECT_EQ(0u, load->warnings.size());
+  EXPECT_TRUE(load->warnings.empty());
 
   EXPECT_EQ("billy joel", flags.name1);
   EXPECT_EQ(43, flags.name2);
@@ -306,7 +306,7 @@ TEST(FlagsTest, LoadFromCommandLineWithNonFlags)
 
   Try<Warnings> load = flags.load("FLAGSTEST_", arraySize(argv), argv);
   EXPECT_SOME(load);
-  EXPECT_EQ(0u, load->warnings.size());
+  EXPECT_TRUE(load->warnings.empty());
 
   EXPECT_EQ("billy joel", flags.name1);
   EXPECT_EQ(43, flags.name2);
@@ -338,7 +338,7 @@ TEST(FlagsTest, LoadFromCommandLineWithDashDash)
 
   Try<Warnings> load = flags.load("FLAGSTEST_", arraySize(argv), argv);
   EXPECT_SOME(load);
-  EXPECT_EQ(0u, load->warnings.size());
+  EXPECT_TRUE(load->warnings.empty());
 
   EXPECT_EQ("billy joel", flags.name1);
   EXPECT_EQ(43, flags.name2);
@@ -373,7 +373,7 @@ TEST(FlagsTest, LoadFromCommandLineAndUpdateArgcArgv)
 
   Try<Warnings> load = flags.load("FLAGSTEST_", &argc, &_argv);
   EXPECT_SOME(load);
-  EXPECT_EQ(0u, load->warnings.size());
+  EXPECT_TRUE(load->warnings.empty());
 
   EXPECT_EQ("billy joel", flags.name1);
   EXPECT_EQ(43, flags.name2);
@@ -541,7 +541,7 @@ TEST_TEMP_DISABLED_ON_WINDOWS(FlagsTest, 
DuplicatesFromEnvironment)
   // `load(prefix, argc, argv)`.
   Try<Warnings> load = flags.load("FLAGSTEST_", arraySize(argv), argv);
   EXPECT_SOME(load);
-  EXPECT_EQ(0u, load->warnings.size());
+  EXPECT_TRUE(load->warnings.empty());
 
   // The environment variables are overwritten by command line flags.
   EXPECT_EQ(flags.name1, "billy joel");
@@ -555,7 +555,7 @@ TEST_TEMP_DISABLED_ON_WINDOWS(FlagsTest, 
DuplicatesFromEnvironment)
     // `load(map<string, string>, unknowns, prefix)`.
     load = flags.load(values, false, "FLAGSTEST_");
     EXPECT_SOME(load);
-    EXPECT_EQ(0u, load->warnings.size());
+    EXPECT_TRUE(load->warnings.empty());
 
     EXPECT_EQ(flags.name1, "billy joel");
     EXPECT_EQ(flags.name2, 50);
@@ -571,7 +571,7 @@ TEST_TEMP_DISABLED_ON_WINDOWS(FlagsTest, 
DuplicatesFromEnvironment)
     load = flags.load(values, false, "FLAGSTEST_");
 
     EXPECT_SOME(load);
-    EXPECT_EQ(0u, load->warnings.size());
+    EXPECT_TRUE(load->warnings.empty());
 
     EXPECT_EQ(flags.name1, "billy joel");
     EXPECT_EQ(flags.name2, 51);

http://git-wip-us.apache.org/repos/asf/mesos/blob/628d6609/3rdparty/stout/tests/multimap_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/tests/multimap_tests.cpp 
b/3rdparty/stout/tests/multimap_tests.cpp
index 36860e4..f0c49f5 100644
--- a/3rdparty/stout/tests/multimap_tests.cpp
+++ b/3rdparty/stout/tests/multimap_tests.cpp
@@ -120,9 +120,9 @@ TYPED_TEST(MultimapTest, Remove)
 
   map.put("foo", 1024);
   map.remove("foo", 1024);
-  ASSERT_EQ(0u, map.get("foo").size());
+  ASSERT_TRUE(map.get("foo").empty());
 
-  ASSERT_EQ(0u, map.size());
+  ASSERT_TRUE(map.empty());
 
   map.put("foo", 1024);
   map.put("foo", 1025);
@@ -131,8 +131,8 @@ TYPED_TEST(MultimapTest, Remove)
   ASSERT_EQ(2u, map.size());
 
   map.remove("foo");
-  ASSERT_EQ(0u, map.get("foo").size());
-  ASSERT_EQ(0u, map.size());
+  ASSERT_TRUE(map.get("foo").empty());
+  ASSERT_TRUE(map.empty());
 }
 
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/628d6609/3rdparty/stout/tests/os/filesystem_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/tests/os/filesystem_tests.cpp 
b/3rdparty/stout/tests/os/filesystem_tests.cpp
index 841f655..0982fd5 100644
--- a/3rdparty/stout/tests/os/filesystem_tests.cpp
+++ b/3rdparty/stout/tests/os/filesystem_tests.cpp
@@ -315,7 +315,7 @@ TEST_F(FsTest, List)
   // Verify that we return empty list when we provide an invalid path.
   Try<list<string>> noFiles = fs::list("this_path_does_not_exist");
   ASSERT_SOME(noFiles);
-  EXPECT_EQ(0u, noFiles.get().size());
+  EXPECT_TRUE(noFiles->empty());
 }
 
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/628d6609/3rdparty/stout/tests/os/process_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/tests/os/process_tests.cpp 
b/3rdparty/stout/tests/os/process_tests.cpp
index 4b5c257..963eb4e 100644
--- a/3rdparty/stout/tests/os/process_tests.cpp
+++ b/3rdparty/stout/tests/os/process_tests.cpp
@@ -166,7 +166,7 @@ TEST_F(ProcessTest, Pids)
 {
   Try<set<pid_t>> pids = os::pids();
   ASSERT_SOME(pids);
-  EXPECT_NE(0u, pids.get().size());
+  EXPECT_FALSE(pids->empty());
   EXPECT_EQ(1u, pids.get().count(getpid()));
 
   // In a FreeBSD jail, pid 1 may not exist.
@@ -242,7 +242,7 @@ TEST_F(ProcessTest, Pstree)
   Try<ProcessTree> tree = os::pstree(getpid());
 
   ASSERT_SOME(tree);
-  EXPECT_EQ(0u, tree.get().children.size()) << stringify(tree.get());
+  EXPECT_TRUE(tree->children.empty()) << stringify(tree.get());
 
   tree =
     Fork(None(),                   // Child.

http://git-wip-us.apache.org/repos/asf/mesos/blob/628d6609/3rdparty/stout/tests/os_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/tests/os_tests.cpp 
b/3rdparty/stout/tests/os_tests.cpp
index e8ecece..959b02d 100644
--- a/3rdparty/stout/tests/os_tests.cpp
+++ b/3rdparty/stout/tests/os_tests.cpp
@@ -344,7 +344,7 @@ TEST_F(OsTest, Children)
   Try<set<pid_t>> children = os::children(getpid());
 
   ASSERT_SOME(children);
-  EXPECT_EQ(0u, children.get().size());
+  EXPECT_TRUE(children->empty());
 
   Try<ProcessTree> tree =
     Fork(None(),                   // Child.

http://git-wip-us.apache.org/repos/asf/mesos/blob/628d6609/3rdparty/stout/tests/proc_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/tests/proc_tests.cpp 
b/3rdparty/stout/tests/proc_tests.cpp
index c6d1d44..b0e3720 100644
--- a/3rdparty/stout/tests/proc_tests.cpp
+++ b/3rdparty/stout/tests/proc_tests.cpp
@@ -43,7 +43,7 @@ TEST(ProcTest, Pids)
   Try<set<pid_t>> pids = proc::pids();
 
   ASSERT_SOME(pids);
-  EXPECT_NE(0u, pids.get().size());
+  EXPECT_FALSE(pids->empty());
   EXPECT_EQ(1u, pids.get().count(getpid()));
   EXPECT_EQ(1u, pids.get().count(1));
 }

http://git-wip-us.apache.org/repos/asf/mesos/blob/628d6609/3rdparty/stout/tests/strings_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/tests/strings_tests.cpp 
b/3rdparty/stout/tests/strings_tests.cpp
index a51144d..395540a 100644
--- a/3rdparty/stout/tests/strings_tests.cpp
+++ b/3rdparty/stout/tests/strings_tests.cpp
@@ -153,14 +153,14 @@ TEST(StringsTest, TokenizeWithMultipleDelims)
 TEST(StringsTest, TokenizeEmptyString)
 {
   vector<string> tokens = strings::tokenize("", " ");
-  ASSERT_EQ(0u, tokens.size());
+  ASSERT_TRUE(tokens.empty());
 }
 
 
 TEST(StringsTest, TokenizeDelimOnlyString)
 {
   vector<string> tokens = strings::tokenize("   ", " ");
-  ASSERT_EQ(0u, tokens.size());
+  ASSERT_TRUE(tokens.empty());
 }
 
 
@@ -201,7 +201,7 @@ TEST(StringsTest, TokenizeNullByteDelim)
 TEST(StringsTest, TokenizeNZero)
 {
   vector<string> tokens = strings::tokenize("foo,bar,,,", ",", 0);
-  ASSERT_EQ(0u, tokens.size());
+  ASSERT_TRUE(tokens.empty());
 }
 
 
@@ -216,7 +216,7 @@ TEST(StringsTest, TokenizeNOne)
 TEST(StringsTest, TokenizeNDelimOnlyString)
 {
   vector<string> tokens = strings::tokenize(",,,", ",", 2);
-  ASSERT_EQ(0u, tokens.size());
+  ASSERT_TRUE(tokens.empty());
 }
 
 
@@ -354,7 +354,7 @@ TEST(StringsTest, SplitWithMultipleDelims)
 TEST(StringsTest, SplitNZero)
 {
   vector<string> tokens = strings::split("foo,bar,,,", ",", 0);
-  ASSERT_EQ(0u, tokens.size());
+  ASSERT_TRUE(tokens.empty());
 }
 
 

Reply via email to