]> granicus.if.org Git - llvm/commitdiff
[VFS] Add isLocal to ProxyFileSystem and add unit tests.
authorMichael J. Spencer <bigcheesegs@gmail.com>
Mon, 17 Dec 2018 22:30:05 +0000 (22:30 +0000)
committerMichael J. Spencer <bigcheesegs@gmail.com>
Mon, 17 Dec 2018 22:30:05 +0000 (22:30 +0000)
Differential Revision: https://reviews.llvm.org/D55789

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349410 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/VirtualFileSystem.h
unittests/Support/VirtualFileSystemTest.cpp

index b3326bbbe486b33322c04d68d48362cc780368eb..3d4094eeb11106c13b27dadbdd7611028b124fe6 100644 (file)
@@ -374,6 +374,9 @@ public:
                               SmallVectorImpl<char> &Output) const override {
     return FS->getRealPath(Path, Output);
   }
+  std::error_code isLocal(const Twine &Path, bool &Result) override {
+    return FS->isLocal(Path, Result);
+  }
 
 protected:
   FileSystem &getUnderlyingFS() { return *FS; }
index 458b07e6d4307d58c4bdb880ce44773a52370e7f..7b42943f0fd969817ac8817eb572203c00528fc6 100644 (file)
@@ -743,6 +743,43 @@ TEST(VirtualFileSystemTest, HiddenInIteration) {
   }
 }
 
+TEST(ProxyFileSystemTest, Basic) {
+  IntrusiveRefCntPtr<vfs::InMemoryFileSystem> Base(
+      new vfs::InMemoryFileSystem());
+  vfs::ProxyFileSystem PFS(Base);
+
+  Base->addFile("/a", 0, MemoryBuffer::getMemBuffer("test"));
+
+  auto Stat = PFS.status("/a");
+  ASSERT_FALSE(Stat.getError());
+
+  auto File = PFS.openFileForRead("/a");
+  ASSERT_FALSE(File.getError());
+  EXPECT_EQ("test", (*(*File)->getBuffer("ignored"))->getBuffer());
+
+  std::error_code EC;
+  vfs::directory_iterator I = PFS.dir_begin("/", EC);
+  ASSERT_FALSE(EC);
+  ASSERT_EQ("/a", I->path());
+  I.increment(EC);
+  ASSERT_FALSE(EC);
+  ASSERT_EQ(vfs::directory_iterator(), I);
+
+  ASSERT_FALSE(PFS.setCurrentWorkingDirectory("/"));
+
+  auto PWD = PFS.getCurrentWorkingDirectory();
+  ASSERT_FALSE(PWD.getError());
+  ASSERT_EQ("/", *PWD);
+
+  SmallString<16> Path;
+  ASSERT_FALSE(PFS.getRealPath("a", Path));
+  ASSERT_EQ("/a", Path);
+
+  bool Local = true;
+  ASSERT_FALSE(PFS.isLocal("/a", Local));
+  ASSERT_EQ(false, Local);
+}
+
 class InMemoryFileSystemTest : public ::testing::Test {
 protected:
   llvm::vfs::InMemoryFileSystem FS;