aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Support/VirtualFileSystemTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/unittests/Support/VirtualFileSystemTest.cpp')
-rw-r--r--llvm/unittests/Support/VirtualFileSystemTest.cpp86
1 files changed, 86 insertions, 0 deletions
diff --git a/llvm/unittests/Support/VirtualFileSystemTest.cpp b/llvm/unittests/Support/VirtualFileSystemTest.cpp
index 54a6e0fb..d4abbb4 100644
--- a/llvm/unittests/Support/VirtualFileSystemTest.cpp
+++ b/llvm/unittests/Support/VirtualFileSystemTest.cpp
@@ -895,6 +895,47 @@ TEST(VirtualFileSystemTest, HiddenInIteration) {
}
}
+TEST(VirtualFileSystemTest, Visit) {
+ IntrusiveRefCntPtr<DummyFileSystem> Base(new DummyFileSystem());
+ IntrusiveRefCntPtr<DummyFileSystem> Middle(new DummyFileSystem());
+ IntrusiveRefCntPtr<DummyFileSystem> Top(new DummyFileSystem());
+ IntrusiveRefCntPtr<vfs::OverlayFileSystem> O(
+ new vfs::OverlayFileSystem(Base));
+ O->pushOverlay(Middle);
+ O->pushOverlay(Top);
+
+ auto YAML =
+ MemoryBuffer::getMemBuffer("{\n"
+ " 'version': 0,\n"
+ " 'redirecting-with': 'redirect-only',\n"
+ " 'roots': [\n"
+ " {\n"
+ " 'type': 'file',\n"
+ " 'name': '/vfile',\n"
+ " 'external-contents': '/a',\n"
+ " },"
+ " ]\n"
+ "}");
+
+ IntrusiveRefCntPtr<vfs::RedirectingFileSystem> Redirecting =
+ vfs::RedirectingFileSystem::create(std::move(YAML), nullptr, "", nullptr,
+ O)
+ .release();
+
+ vfs::ProxyFileSystem PFS(Redirecting);
+
+ std::vector<const vfs::FileSystem *> FSs;
+ PFS.visit([&](const vfs::FileSystem &FS) { FSs.push_back(&FS); });
+
+ ASSERT_EQ(size_t(6), FSs.size());
+ EXPECT_TRUE(isa<vfs::ProxyFileSystem>(FSs[0]));
+ EXPECT_TRUE(isa<vfs::RedirectingFileSystem>(FSs[1]));
+ EXPECT_TRUE(isa<vfs::OverlayFileSystem>(FSs[2]));
+ EXPECT_TRUE(isa<vfs::FileSystem>(FSs[3]));
+ EXPECT_TRUE(isa<vfs::FileSystem>(FSs[4]));
+ EXPECT_TRUE(isa<vfs::FileSystem>(FSs[5]));
+}
+
TEST(OverlayFileSystemTest, PrintOutput) {
auto Dummy = makeIntrusiveRefCnt<DummyFileSystem>();
auto Overlay1 = makeIntrusiveRefCnt<vfs::OverlayFileSystem>(Dummy);
@@ -3244,3 +3285,48 @@ TEST(RedirectingFileSystemTest, PrintOutput) {
" DummyFileSystem (RecursiveContents)\n",
Output);
}
+
+TEST(RedirectingFileSystemTest, Used) {
+ auto Dummy = makeIntrusiveRefCnt<DummyFileSystem>();
+ auto YAML1 =
+ MemoryBuffer::getMemBuffer("{\n"
+ " 'version': 0,\n"
+ " 'redirecting-with': 'fallthrough',\n"
+ " 'roots': [\n"
+ " {\n"
+ " 'type': 'file',\n"
+ " 'name': '/vfile1',\n"
+ " 'external-contents': '/a',\n"
+ " },"
+ " ]\n"
+ "}");
+ auto YAML2 =
+ MemoryBuffer::getMemBuffer("{\n"
+ " 'version': 0,\n"
+ " 'redirecting-with': 'fallthrough',\n"
+ " 'roots': [\n"
+ " {\n"
+ " 'type': 'file',\n"
+ " 'name': '/vfile2',\n"
+ " 'external-contents': '/b',\n"
+ " },"
+ " ]\n"
+ "}");
+
+ Dummy->addRegularFile("/a");
+ Dummy->addRegularFile("/b");
+
+ IntrusiveRefCntPtr<vfs::RedirectingFileSystem> Redirecting1 =
+ vfs::RedirectingFileSystem::create(std::move(YAML1), nullptr, "", nullptr,
+ Dummy)
+ .release();
+ auto Redirecting2 = vfs::RedirectingFileSystem::create(
+ std::move(YAML2), nullptr, "", nullptr, Redirecting1);
+
+ Redirecting1->setUsageTrackingActive(true);
+ Redirecting2->setUsageTrackingActive(true);
+ EXPECT_TRUE(Redirecting2->exists("/vfile1"));
+ EXPECT_TRUE(Redirecting2->exists("/b"));
+ EXPECT_TRUE(Redirecting1->hasBeenUsed());
+ EXPECT_FALSE(Redirecting2->hasBeenUsed());
+}