[llvm] r349410 - [VFS] Add isLocal to ProxyFileSystem and add unit tests.

Michael J. Spencer via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 17 14:30:05 PST 2018


Author: mspencer
Date: Mon Dec 17 14:30:05 2018
New Revision: 349410

URL: http://llvm.org/viewvc/llvm-project?rev=349410&view=rev
Log:
[VFS] Add isLocal to ProxyFileSystem and add unit tests.

Differential Revision: https://reviews.llvm.org/D55789

Modified:
    llvm/trunk/include/llvm/Support/VirtualFileSystem.h
    llvm/trunk/unittests/Support/VirtualFileSystemTest.cpp

Modified: llvm/trunk/include/llvm/Support/VirtualFileSystem.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/VirtualFileSystem.h?rev=349410&r1=349409&r2=349410&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/VirtualFileSystem.h (original)
+++ llvm/trunk/include/llvm/Support/VirtualFileSystem.h Mon Dec 17 14:30:05 2018
@@ -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; }

Modified: llvm/trunk/unittests/Support/VirtualFileSystemTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/VirtualFileSystemTest.cpp?rev=349410&r1=349409&r2=349410&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/VirtualFileSystemTest.cpp (original)
+++ llvm/trunk/unittests/Support/VirtualFileSystemTest.cpp Mon Dec 17 14:30:05 2018
@@ -743,6 +743,43 @@ TEST(VirtualFileSystemTest, HiddenInIter
   }
 }
 
+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;




More information about the llvm-commits mailing list