aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Basic/VirtualFileSystemTest.cpp
diff options
context:
space:
mode:
authorEric Liu <ioeric@google.com>2018-05-18 13:22:49 +0000
committerEric Liu <ioeric@google.com>2018-05-18 13:22:49 +0000
commita840a465579a91418575c77ca6c04ded28f55b1a (patch)
tree9b0ce6636eb8df0197e8b5d100ed8960cb3c78c1 /clang/unittests/Basic/VirtualFileSystemTest.cpp
parent215e4718caa1529ff48471f8a179fb530fd1838d (diff)
downloadllvm-a840a465579a91418575c77ca6c04ded28f55b1a.zip
llvm-a840a465579a91418575c77ca6c04ded28f55b1a.tar.gz
llvm-a840a465579a91418575c77ca6c04ded28f55b1a.tar.bz2
[VFS] Implement getRealPath for OverlayFileSystem.
Reviewers: bkramer Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D47060 llvm-svn: 332717
Diffstat (limited to 'clang/unittests/Basic/VirtualFileSystemTest.cpp')
-rw-r--r--clang/unittests/Basic/VirtualFileSystemTest.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/clang/unittests/Basic/VirtualFileSystemTest.cpp b/clang/unittests/Basic/VirtualFileSystemTest.cpp
index 383c1ff..673eca8 100644
--- a/clang/unittests/Basic/VirtualFileSystemTest.cpp
+++ b/clang/unittests/Basic/VirtualFileSystemTest.cpp
@@ -67,6 +67,21 @@ public:
std::error_code setCurrentWorkingDirectory(const Twine &Path) override {
return std::error_code();
}
+ // Map any symlink to "/symlink".
+ std::error_code getRealPath(const Twine &Path,
+ SmallVectorImpl<char> &Output) const override {
+ auto I = FilesAndDirs.find(Path.str());
+ if (I == FilesAndDirs.end())
+ return make_error_code(llvm::errc::no_such_file_or_directory);
+ if (I->second.isSymlink()) {
+ Output.clear();
+ Twine("/symlink").toVector(Output);
+ return std::error_code();
+ }
+ Output.clear();
+ Path.toVector(Output);
+ return std::error_code();
+ }
struct DirIterImpl : public clang::vfs::detail::DirIterImpl {
std::map<std::string, vfs::Status> &FilesAndDirs;
@@ -196,6 +211,35 @@ TEST(VirtualFileSystemTest, BaseOnlyOverlay) {
EXPECT_TRUE(Status->equivalent(*Status2));
}
+TEST(VirtualFileSystemTest, GetRealPathInOverlay) {
+ IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem());
+ Lower->addRegularFile("/foo");
+ Lower->addSymlink("/lower_link");
+ IntrusiveRefCntPtr<DummyFileSystem> Upper(new DummyFileSystem());
+
+ IntrusiveRefCntPtr<vfs::OverlayFileSystem> O(
+ new vfs::OverlayFileSystem(Lower));
+ O->pushOverlay(Upper);
+
+ // Regular file.
+ SmallString<16> RealPath;
+ EXPECT_FALSE(O->getRealPath("/foo", RealPath));
+ EXPECT_EQ(RealPath.str(), "/foo");
+
+ // Expect no error getting real path for symlink in lower overlay.
+ EXPECT_FALSE(O->getRealPath("/lower_link", RealPath));
+ EXPECT_EQ(RealPath.str(), "/symlink");
+
+ // Try a non-existing link.
+ EXPECT_EQ(O->getRealPath("/upper_link", RealPath),
+ errc::no_such_file_or_directory);
+
+ // Add a new symlink in upper.
+ Upper->addSymlink("/upper_link");
+ EXPECT_FALSE(O->getRealPath("/upper_link", RealPath));
+ EXPECT_EQ(RealPath.str(), "/symlink");
+}
+
TEST(VirtualFileSystemTest, OverlayFiles) {
IntrusiveRefCntPtr<DummyFileSystem> Base(new DummyFileSystem());
IntrusiveRefCntPtr<DummyFileSystem> Middle(new DummyFileSystem());