Added a unit test for path::join.

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


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

Branch: refs/heads/master
Commit: fea27355b9254edbf29f7ab996d49ef5020ac17f
Parents: 623d6a0
Author: Cody Maloney <[email protected]>
Authored: Thu Nov 13 11:01:05 2014 -0800
Committer: Benjamin Mahler <[email protected]>
Committed: Thu Nov 13 11:01:05 2014 -0800

----------------------------------------------------------------------
 3rdparty/libprocess/3rdparty/stout/Makefile.am  |  1 +
 .../3rdparty/stout/include/stout/path.hpp       |  2 +-
 .../3rdparty/stout/tests/path_tests.cpp         | 47 ++++++++++++++++++++
 3 files changed, 49 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/fea27355/3rdparty/libprocess/3rdparty/stout/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/Makefile.am 
b/3rdparty/libprocess/3rdparty/stout/Makefile.am
index 7aac3fd..8e51957 100644
--- a/3rdparty/libprocess/3rdparty/stout/Makefile.am
+++ b/3rdparty/libprocess/3rdparty/stout/Makefile.am
@@ -32,6 +32,7 @@ EXTRA_DIST =                                  \
   tests/os_tests.cpp                           \
   tests/os/sendfile_tests.cpp                  \
   tests/os/signals_tests.cpp                   \
+  tests/path_tests.cpp                         \
   tests/proc_tests.cpp                         \
   tests/protobuf_tests.cpp                     \
   tests/protobuf_tests.pb.cc                   \

http://git-wip-us.apache.org/repos/asf/mesos/blob/fea27355/3rdparty/libprocess/3rdparty/stout/include/stout/path.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/path.hpp 
b/3rdparty/libprocess/3rdparty/stout/include/stout/path.hpp
index bc6920a..4f7153e 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/path.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/path.hpp
@@ -17,7 +17,7 @@
 #include <string>
 #include <vector>
 
-#include "strings.hpp"
+#include <stout/strings.hpp>
 
 namespace path {
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/fea27355/3rdparty/libprocess/3rdparty/stout/tests/path_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/tests/path_tests.cpp 
b/3rdparty/libprocess/3rdparty/stout/tests/path_tests.cpp
new file mode 100644
index 0000000..18dd8e7
--- /dev/null
+++ b/3rdparty/libprocess/3rdparty/stout/tests/path_tests.cpp
@@ -0,0 +1,47 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <gtest/gtest.h>
+
+#include <string>
+#include <vector>
+
+#include <stout/path.hpp>
+
+using std::string;
+using std::vector;
+
+
+TEST(PathTest, Join)
+{
+  // Raw strings and std::strings can be mixed.
+  EXPECT_EQ("a/b/c", path::join("a", "b", "c"));
+  EXPECT_EQ("a/b/c", path::join(string("a"), string("b"), string("c")));
+  EXPECT_EQ("a/b/c", path::join(string("a"), "b", string("c")));
+
+  // Joining a vector of strings.
+  EXPECT_EQ("a/b/c", path::join(vector<string>({"a", "b", "c"})));
+  EXPECT_EQ("", path::join(vector<string>()));
+  //TODO(cmaloney): This should join to ""
+  EXPECT_EQ("/", path::join(vector<string>({"", "", ""})));
+
+  // Interesting corner cases around being the first, middle, last.
+  EXPECT_EQ("/asdf", path::join("/", "asdf"));
+  EXPECT_EQ("/", path::join("", "/", ""));
+
+  // Check trailing and leading slashes get cleaned up how we expect.
+  EXPECT_EQ("a/b/c/", path::join("a/", "b/", "c/"));
+  EXPECT_EQ("/a/b/c", path::join("/a", "/b", "/c"));
+  EXPECT_EQ("/a/b/c/", path::join("/a/", "/b/", "/c/"));
+  EXPECT_EQ("a/b/c/", path::join("a/", "/b/", "/c/"));
+}

Reply via email to