proxygen
FsUtilTest.cpp File Reference
#include <folly/experimental/io/FsUtil.h>
#include <glog/logging.h>
#include <folly/portability/GTest.h>

Go to the source code of this file.

Functions

 TEST (Simple, Path)
 
 TEST (Simple, CanonicalizeParent)
 

Function Documentation

TEST ( Simple  ,
Path   
)

Definition at line 26 of file FsUtilTest.cpp.

References EXPECT_EQ, EXPECT_FALSE, EXPECT_THROW, EXPECT_TRUE, folly::fs::remove_prefix(), and folly::fs::starts_with().

26  {
27  path root("/");
28  path abs1("/hello/world");
29  path rel1("meow");
30  EXPECT_TRUE(starts_with(abs1, root));
31  EXPECT_FALSE(starts_with(rel1, root));
32  EXPECT_EQ(path("hello/world"), remove_prefix(abs1, root));
33  EXPECT_THROW({ remove_prefix(rel1, root); }, filesystem_error);
34 
35  path abs2("/hello");
36  path abs3("/hello/");
37  path abs4("/hello/world");
38  path abs5("/hello/world/");
39  path abs6("/hello/wo");
40  EXPECT_TRUE(starts_with(abs1, abs2));
41  EXPECT_TRUE(starts_with(abs1, abs3));
42  EXPECT_TRUE(starts_with(abs1, abs4));
43  EXPECT_FALSE(starts_with(abs1, abs5));
44  EXPECT_FALSE(starts_with(abs1, abs6));
45  EXPECT_EQ(path("world"), remove_prefix(abs1, abs2));
46  EXPECT_EQ(path("world"), remove_prefix(abs1, abs3));
47  EXPECT_EQ(path(), remove_prefix(abs1, abs4));
48  EXPECT_THROW({ remove_prefix(abs1, abs5); }, filesystem_error);
49  EXPECT_THROW({ remove_prefix(abs1, abs6); }, filesystem_error);
50 }
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
path remove_prefix(const path &pth, const path &prefix)
Definition: FsUtil.cpp:50
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
bool starts_with(const path &pth, const path &prefix)
Definition: FsUtil.cpp:45
TEST ( Simple  ,
CanonicalizeParent   
)

Definition at line 52 of file FsUtilTest.cpp.

References a, b, c, folly::fs::canonical_parent(), EXPECT_EQ, and EXPECT_THROW.

52  {
53  path a("/usr/bin/tail");
54  path b("/usr/lib/../bin/tail");
55  path c("/usr/bin/DOES_NOT_EXIST_ASDF");
56  path d("/usr/lib/../bin/DOES_NOT_EXIST_ASDF");
57 
58  EXPECT_EQ(a, canonical(a));
60  EXPECT_EQ(a, canonical(b));
62  EXPECT_THROW({ canonical(c); }, filesystem_error);
63  EXPECT_THROW({ canonical(d); }, filesystem_error);
66 }
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
char b
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
char a
char c
path canonical_parent(const path &pth, const path &base)
Definition: FsUtil.cpp:68