X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=unittests%2FSupport%2FPath.cpp;h=cfba227dbe93fe723d855d95bcb15a418ba916ec;hb=3d7575d7e2e8bdb6603f6754dfa86aacf1a4bbf3;hp=00af989f48571efd2dff3d2e162ce2b0b793c885;hpb=a4beb9e37257a6e53d5d5b3ea5fd05d9d48845d3;p=oota-llvm.git diff --git a/unittests/Support/Path.cpp b/unittests/Support/Path.cpp index 00af989f485..cfba227dbe9 100644 --- a/unittests/Support/Path.cpp +++ b/unittests/Support/Path.cpp @@ -16,10 +16,14 @@ #include "gtest/gtest.h" #ifdef LLVM_ON_WIN32 -#include +#include #include #endif +#ifdef LLVM_ON_UNIX +#include +#endif + using namespace llvm; using namespace llvm::sys; @@ -168,6 +172,26 @@ TEST(Support, RelativePathIterator) { } } +TEST(Support, RelativePathDotIterator) { + SmallString<64> Path(StringRef(".c/.d/../.")); + typedef SmallVector PathComponents; + PathComponents ExpectedPathComponents; + PathComponents ActualPathComponents; + + StringRef(Path).split(ExpectedPathComponents, "/"); + + for (path::const_iterator I = path::begin(Path), E = path::end(Path); I != E; + ++I) { + ActualPathComponents.push_back(*I); + } + + ASSERT_EQ(ExpectedPathComponents.size(), ActualPathComponents.size()); + + for (size_t i = 0; i Path(StringRef("/c/d/e/foo.txt")); typedef SmallVector PathComponents; @@ -191,6 +215,29 @@ TEST(Support, AbsolutePathIterator) { } } +TEST(Support, AbsolutePathDotIterator) { + SmallString<64> Path(StringRef("/.c/.d/../.")); + typedef SmallVector PathComponents; + PathComponents ExpectedPathComponents; + PathComponents ActualPathComponents; + + StringRef(Path).split(ExpectedPathComponents, "/"); + + // The root path will also be a component when iterating + ExpectedPathComponents[0] = "/"; + + for (path::const_iterator I = path::begin(Path), E = path::end(Path); I != E; + ++I) { + ActualPathComponents.push_back(*I); + } + + ASSERT_EQ(ExpectedPathComponents.size(), ActualPathComponents.size()); + + for (size_t i = 0; i Path(StringRef("c:\\c\\e\\foo.txt")); @@ -265,7 +312,7 @@ protected: /// be placed. It is removed at the end of each test (must be empty). SmallString<128> TestDirectory; - virtual void SetUp() { + void SetUp() override { ASSERT_NO_ERROR( fs::createUniqueDirectory("file-system-test", TestDirectory)); // We don't care about this specific file. @@ -273,9 +320,7 @@ protected: errs().flush(); } - virtual void TearDown() { - ASSERT_NO_ERROR(fs::remove(TestDirectory.str())); - } + void TearDown() override { ASSERT_NO_ERROR(fs::remove(TestDirectory.str())); } }; TEST_F(FileSystemTest, Unique) { @@ -417,6 +462,26 @@ TEST_F(FileSystemTest, CreateDir) { errc::file_exists); ASSERT_NO_ERROR(fs::remove(Twine(TestDirectory) + "foo")); +#ifdef LLVM_ON_UNIX + // Set a 0000 umask so that we can test our directory permissions. + mode_t OldUmask = ::umask(0000); + + fs::file_status Status; + ASSERT_NO_ERROR( + fs::create_directory(Twine(TestDirectory) + "baz500", false, + fs::perms::owner_read | fs::perms::owner_exe)); + ASSERT_NO_ERROR(fs::status(Twine(TestDirectory) + "baz500", Status)); + ASSERT_EQ(Status.permissions() & fs::perms::all_all, + fs::perms::owner_read | fs::perms::owner_exe); + ASSERT_NO_ERROR(fs::create_directory(Twine(TestDirectory) + "baz777", false, + fs::perms::all_all)); + ASSERT_NO_ERROR(fs::status(Twine(TestDirectory) + "baz777", Status)); + ASSERT_EQ(Status.permissions() & fs::perms::all_all, fs::perms::all_all); + + // Restore umask to be safe. + ::umask(OldUmask); +#endif + #ifdef LLVM_ON_WIN32 // Prove that create_directories() can handle a pathname > 248 characters, // which is the documented limit for CreateDirectory(). @@ -724,4 +789,14 @@ TEST(Support, NormalizePath) { #undef EXPECT_PATH_IS } + +TEST(Support, RemoveLeadingDotSlash) { + StringRef Path1("././/foolz/wat"); + StringRef Path2("./////"); + + Path1 = path::remove_leading_dotslash(Path1); + EXPECT_EQ(Path1, "foolz/wat"); + Path2 = path::remove_leading_dotslash(Path2); + EXPECT_EQ(Path2, ""); +} } // anonymous namespace