diff options
| author | Jan Svoboda <jan_svoboda@apple.com> | 2025-10-15 09:24:36 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-15 09:24:36 -0700 |
| commit | 9deba01c1d5db607da5b943bd5a6185384608605 (patch) | |
| tree | 09bf4de993552d23cb93127acbdf71c87daf26b1 /llvm/unittests/Support/SourceMgrTest.cpp | |
| parent | 097f1e7625966673b881df63a241f755317b0bb9 (diff) | |
| download | llvm-9deba01c1d5db607da5b943bd5a6185384608605.zip llvm-9deba01c1d5db607da5b943bd5a6185384608605.tar.gz llvm-9deba01c1d5db607da5b943bd5a6185384608605.tar.bz2 | |
[support] Use VFS in `SourceMgr` for loading includes (#162903)
Most `SourceMgr` clients don't make use of include files, but those that
do might want to specify the file system to use. This patch enables that
by making it possible to pass a `vfs::FileSystem` instance into
`SourceMgr`.
Diffstat (limited to 'llvm/unittests/Support/SourceMgrTest.cpp')
| -rw-r--r-- | llvm/unittests/Support/SourceMgrTest.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/llvm/unittests/Support/SourceMgrTest.cpp b/llvm/unittests/Support/SourceMgrTest.cpp index 301b64f..c65f001 100644 --- a/llvm/unittests/Support/SourceMgrTest.cpp +++ b/llvm/unittests/Support/SourceMgrTest.cpp @@ -8,6 +8,7 @@ #include "llvm/Support/SourceMgr.h" #include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/VirtualFileSystem.h" #include "llvm/Support/raw_ostream.h" #include "gtest/gtest.h" @@ -506,3 +507,13 @@ TEST_F(SourceMgrTest, PrintWithoutLoc) { Diag.print(nullptr, OS, false, false, false); EXPECT_EQ("message\n", Output); } + +TEST_F(SourceMgrTest, IncludeDirs) { + auto VFS = makeIntrusiveRefCnt<vfs::InMemoryFileSystem>(); + VFS->addFile("include/file", 0, MemoryBuffer::getMemBuffer("contents")); + SM.setVirtualFileSystem(std::move(VFS)); + SM.setIncludeDirs({"include"}); + std::string ResolvedPath; + unsigned NumBuffers = SM.AddIncludeFile("file", SMLoc(), ResolvedPath); + EXPECT_EQ(NumBuffers, 1u); +} |
