summaryrefslogtreecommitdiffstats
path: root/gnu/llvm/tools/clang/unittests/Basic/VirtualFileSystemTest.cpp
diff options
context:
space:
mode:
authorpatrick <patrick@openbsd.org>2017-10-04 20:27:34 +0000
committerpatrick <patrick@openbsd.org>2017-10-04 20:27:34 +0000
commit31eb748944903b7f4f38afda9851951ca9dfc1ae (patch)
tree9b95b6ea45d0874d75eb05b90c0840e191416439 /gnu/llvm/tools/clang/unittests/Basic/VirtualFileSystemTest.cpp
parentDon't try to handle IPv4-compatible IPv6 addresses (diff)
downloadwireguard-openbsd-31eb748944903b7f4f38afda9851951ca9dfc1ae.tar.xz
wireguard-openbsd-31eb748944903b7f4f38afda9851951ca9dfc1ae.zip
Import LLVM 5.0.0 release including clang, lld and lldb.
Diffstat (limited to 'gnu/llvm/tools/clang/unittests/Basic/VirtualFileSystemTest.cpp')
-rw-r--r--gnu/llvm/tools/clang/unittests/Basic/VirtualFileSystemTest.cpp106
1 files changed, 105 insertions, 1 deletions
diff --git a/gnu/llvm/tools/clang/unittests/Basic/VirtualFileSystemTest.cpp b/gnu/llvm/tools/clang/unittests/Basic/VirtualFileSystemTest.cpp
index 580343d93ea..40add2195b5 100644
--- a/gnu/llvm/tools/clang/unittests/Basic/VirtualFileSystemTest.cpp
+++ b/gnu/llvm/tools/clang/unittests/Basic/VirtualFileSystemTest.cpp
@@ -300,8 +300,26 @@ struct ScopedDir {
EXPECT_FALSE(EC);
}
~ScopedDir() {
- if (Path != "")
+ if (Path != "") {
EXPECT_FALSE(llvm::sys::fs::remove(Path.str()));
+ }
+ }
+ operator StringRef() { return Path.str(); }
+};
+
+struct ScopedLink {
+ SmallString<128> Path;
+ ScopedLink(const Twine &To, const Twine &From) {
+ Path = From.str();
+ std::error_code EC = sys::fs::create_link(To, From);
+ if (EC)
+ Path = "";
+ EXPECT_FALSE(EC);
+ }
+ ~ScopedLink() {
+ if (Path != "") {
+ EXPECT_FALSE(llvm::sys::fs::remove(Path.str()));
+ }
}
operator StringRef() { return Path.str(); }
};
@@ -334,6 +352,42 @@ TEST(VirtualFileSystemTest, BasicRealFSIteration) {
EXPECT_EQ(vfs::directory_iterator(), I);
}
+#ifdef LLVM_ON_UNIX
+TEST(VirtualFileSystemTest, BrokenSymlinkRealFSIteration) {
+ ScopedDir TestDirectory("virtual-file-system-test", /*Unique*/ true);
+ IntrusiveRefCntPtr<vfs::FileSystem> FS = vfs::getRealFileSystem();
+
+ ScopedLink _a("no_such_file", TestDirectory + "/a");
+ ScopedDir _b(TestDirectory + "/b");
+ ScopedLink _c("no_such_file", TestDirectory + "/c");
+
+ std::error_code EC;
+ for (vfs::directory_iterator I = FS->dir_begin(Twine(TestDirectory), EC), E;
+ I != E; I.increment(EC)) {
+ // Skip broken symlinks.
+ auto EC2 = std::make_error_code(std::errc::no_such_file_or_directory);
+ if (EC == EC2) {
+ EC.clear();
+ continue;
+ }
+ // For bot debugging.
+ if (EC) {
+ outs() << "Error code found:\n"
+ << "EC value: " << EC.value() << "\n"
+ << "EC category: " << EC.category().name()
+ << "EC message: " << EC.message() << "\n";
+
+ outs() << "Error code tested for:\n"
+ << "EC value: " << EC2.value() << "\n"
+ << "EC category: " << EC2.category().name()
+ << "EC message: " << EC2.message() << "\n";
+ }
+ ASSERT_FALSE(EC);
+ EXPECT_TRUE(I->getName() == _b);
+ }
+}
+#endif
+
TEST(VirtualFileSystemTest, BasicRealFSRecursiveIteration) {
ScopedDir TestDirectory("virtual-file-system-test", /*Unique*/true);
IntrusiveRefCntPtr<vfs::FileSystem> FS = vfs::getRealFileSystem();
@@ -373,6 +427,56 @@ TEST(VirtualFileSystemTest, BasicRealFSRecursiveIteration) {
EXPECT_EQ(1, Counts[3]); // d
}
+#ifdef LLVM_ON_UNIX
+TEST(VirtualFileSystemTest, BrokenSymlinkRealFSRecursiveIteration) {
+ ScopedDir TestDirectory("virtual-file-system-test", /*Unique*/ true);
+ IntrusiveRefCntPtr<vfs::FileSystem> FS = vfs::getRealFileSystem();
+
+ ScopedLink _a("no_such_file", TestDirectory + "/a");
+ ScopedDir _b(TestDirectory + "/b");
+ ScopedLink _ba("no_such_file", TestDirectory + "/b/a");
+ ScopedDir _bb(TestDirectory + "/b/b");
+ ScopedLink _bc("no_such_file", TestDirectory + "/b/c");
+ ScopedLink _c("no_such_file", TestDirectory + "/c");
+ ScopedDir _d(TestDirectory + "/d");
+ ScopedDir _dd(TestDirectory + "/d/d");
+ ScopedDir _ddd(TestDirectory + "/d/d/d");
+ ScopedLink _e("no_such_file", TestDirectory + "/e");
+ std::vector<StringRef> Expected = {_b, _bb, _d, _dd, _ddd};
+
+ std::vector<std::string> Contents;
+ std::error_code EC;
+ for (vfs::recursive_directory_iterator I(*FS, Twine(TestDirectory), EC), E;
+ I != E; I.increment(EC)) {
+ // Skip broken symlinks.
+ auto EC2 = std::make_error_code(std::errc::no_such_file_or_directory);
+ if (EC == EC2) {
+ EC.clear();
+ continue;
+ }
+ // For bot debugging.
+ if (EC) {
+ outs() << "Error code found:\n"
+ << "EC value: " << EC.value() << "\n"
+ << "EC category: " << EC.category().name()
+ << "EC message: " << EC.message() << "\n";
+
+ outs() << "Error code tested for:\n"
+ << "EC value: " << EC2.value() << "\n"
+ << "EC category: " << EC2.category().name()
+ << "EC message: " << EC2.message() << "\n";
+ }
+ ASSERT_FALSE(EC);
+ Contents.push_back(I->getName());
+ }
+
+ // Check sorted contents.
+ std::sort(Contents.begin(), Contents.end());
+ EXPECT_EQ(Expected.size(), Contents.size());
+ EXPECT_TRUE(std::equal(Contents.begin(), Contents.end(), Expected.begin()));
+}
+#endif
+
template <typename DirIter>
static void checkContents(DirIter I, ArrayRef<StringRef> ExpectedOut) {
std::error_code EC;