diff options
author | Ben Barham <ben_barham@apple.com> | 2022-03-09 12:23:22 -0800 |
---|---|---|
committer | Ben Barham <ben_barham@apple.com> | 2022-03-17 13:02:40 -0700 |
commit | 4125524112e00c61547e83804279ef7889c8636a (patch) | |
tree | f8a409025335012bb8476efcf628adfc0886b755 /llvm/unittests/Support/VirtualFileSystemTest.cpp | |
parent | b4cc3b1dd8d7200640210513263b28187f810703 (diff) | |
download | llvm-4125524112e00c61547e83804279ef7889c8636a.zip llvm-4125524112e00c61547e83804279ef7889c8636a.tar.gz llvm-4125524112e00c61547e83804279ef7889c8636a.tar.bz2 |
[VFS] Add print/dump to the whole FileSystem hierarchy
For now most are implemented by printing out the name of the filesystem,
but this can be expanded in the future. Only `OverlayFileSystem` and
`RedirectingFileSystem` are properly implemented in this patch.
- `OverlayFileSystem`: Prints each filesystem in the order that any
operations are actually run on them. Optionally prints recursively.
- `RedirectingFileSystem`: Prints out all mappings, as well as the
`ExternalFS`. Most of this was already implemented other than the
handling for the `DirectoryRemap` case and to actually print out the
mapping.
Each FS should implement `printImpl` rather than `print`, where the
latter just fowards to the former. This is to avoid spreading the
default arguments through to the subclasses (where we may miss updating
in the future).
Differential Revision: https://reviews.llvm.org/D121421
Diffstat (limited to 'llvm/unittests/Support/VirtualFileSystemTest.cpp')
-rw-r--r-- | llvm/unittests/Support/VirtualFileSystemTest.cpp | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/llvm/unittests/Support/VirtualFileSystemTest.cpp b/llvm/unittests/Support/VirtualFileSystemTest.cpp index 657fc0a..1eb7fe6 100644 --- a/llvm/unittests/Support/VirtualFileSystemTest.cpp +++ b/llvm/unittests/Support/VirtualFileSystemTest.cpp @@ -171,6 +171,25 @@ public: sys::fs::file_type::symlink_file, sys::fs::all_all); addEntry(Path, S); } + +protected: + void printImpl(raw_ostream &OS, PrintType Type, + unsigned IndentLevel) const override { + printIndent(OS, IndentLevel); + OS << "DummyFileSystem ("; + switch (Type) { + case vfs::FileSystem::PrintType::Summary: + OS << "Summary"; + break; + case vfs::FileSystem::PrintType::Contents: + OS << "Contents"; + break; + case vfs::FileSystem::PrintType::RecursiveContents: + OS << "RecursiveContents"; + break; + } + OS << ")\n"; + } }; class ErrorDummyFileSystem : public DummyFileSystem { @@ -848,6 +867,36 @@ TEST(VirtualFileSystemTest, HiddenInIteration) { } } +TEST(OverlayFileSystemTest, PrintOutput) { + auto Dummy = makeIntrusiveRefCnt<DummyFileSystem>(); + auto Overlay1 = makeIntrusiveRefCnt<vfs::OverlayFileSystem>(Dummy); + Overlay1->pushOverlay(Dummy); + auto Overlay2 = makeIntrusiveRefCnt<vfs::OverlayFileSystem>(Overlay1); + Overlay2->pushOverlay(Dummy); + + SmallString<0> Output; + raw_svector_ostream OuputStream{Output}; + + Overlay2->print(OuputStream, vfs::FileSystem::PrintType::Summary); + ASSERT_EQ("OverlayFileSystem\n", Output); + + Output.clear(); + Overlay2->print(OuputStream, vfs::FileSystem::PrintType::Contents); + ASSERT_EQ("OverlayFileSystem\n" + " DummyFileSystem (Summary)\n" + " OverlayFileSystem\n", + Output); + + Output.clear(); + Overlay2->print(OuputStream, vfs::FileSystem::PrintType::RecursiveContents); + ASSERT_EQ("OverlayFileSystem\n" + " DummyFileSystem (RecursiveContents)\n" + " OverlayFileSystem\n" + " DummyFileSystem (RecursiveContents)\n" + " DummyFileSystem (RecursiveContents)\n", + Output); +} + TEST(ProxyFileSystemTest, Basic) { IntrusiveRefCntPtr<vfs::InMemoryFileSystem> Base( new vfs::InMemoryFileSystem()); @@ -2928,3 +2977,80 @@ TEST(VFSFromRemappedFilesTest, LastMappingWins) { EXPECT_EQ("contents of c", (*BufferKeepA)->getBuffer()); EXPECT_EQ("contents of c", (*BufferExternalA)->getBuffer()); } + +TEST(RedirectingFileSystemTest, PrintOutput) { + auto Buffer = + MemoryBuffer::getMemBuffer("{\n" + " 'version': 0,\n" + " 'roots': [\n" + " {\n" + " 'type': 'directory-remap',\n" + " 'name': '/dremap',\n" + " 'external-contents': '/a',\n" + " }," + " {\n" + " 'type': 'directory',\n" + " 'name': '/vdir',\n" + " 'contents': [" + " {\n" + " 'type': 'directory-remap',\n" + " 'name': 'dremap',\n" + " 'external-contents': '/b'\n" + " 'use-external-name': 'true'\n" + " },\n" + " {\n" + " 'type': 'file',\n" + " 'name': 'vfile',\n" + " 'external-contents': '/c'\n" + " 'use-external-name': 'false'\n" + " }]\n" + " }]\n" + "}"); + + auto Dummy = makeIntrusiveRefCnt<DummyFileSystem>(); + auto Redirecting = vfs::RedirectingFileSystem::create( + std::move(Buffer), nullptr, "", nullptr, Dummy); + + SmallString<0> Output; + raw_svector_ostream OuputStream{Output}; + + Redirecting->print(OuputStream, vfs::FileSystem::PrintType::Summary); + ASSERT_EQ("RedirectingFileSystem (UseExternalNames: true)\n", Output); + + Output.clear(); + Redirecting->print(OuputStream, vfs::FileSystem::PrintType::Contents); + ASSERT_EQ("RedirectingFileSystem (UseExternalNames: true)\n" + "'/'\n" + " 'dremap' -> '/a'\n" + " 'vdir'\n" + " 'dremap' -> '/b' (UseExternalName: true)\n" + " 'vfile' -> '/c' (UseExternalName: false)\n" + "ExternalFS:\n" + " DummyFileSystem (Summary)\n", + Output); + + Output.clear(); + Redirecting->print(OuputStream, vfs::FileSystem::PrintType::Contents, 1); + ASSERT_EQ(" RedirectingFileSystem (UseExternalNames: true)\n" + " '/'\n" + " 'dremap' -> '/a'\n" + " 'vdir'\n" + " 'dremap' -> '/b' (UseExternalName: true)\n" + " 'vfile' -> '/c' (UseExternalName: false)\n" + " ExternalFS:\n" + " DummyFileSystem (Summary)\n", + Output); + + Output.clear(); + Redirecting->print(OuputStream, + vfs::FileSystem::PrintType::RecursiveContents); + ASSERT_EQ("RedirectingFileSystem (UseExternalNames: true)\n" + "'/'\n" + " 'dremap' -> '/a'\n" + " 'vdir'\n" + " 'dremap' -> '/b' (UseExternalName: true)\n" + " 'vfile' -> '/c' (UseExternalName: false)\n" + "ExternalFS:\n" + " DummyFileSystem (RecursiveContents)\n", + Output); +} |