aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Support/SourceMgrTest.cpp
diff options
context:
space:
mode:
authorJan Svoboda <jan_svoboda@apple.com>2025-10-15 09:24:36 -0700
committerGitHub <noreply@github.com>2025-10-15 09:24:36 -0700
commit9deba01c1d5db607da5b943bd5a6185384608605 (patch)
tree09bf4de993552d23cb93127acbdf71c87daf26b1 /llvm/unittests/Support/SourceMgrTest.cpp
parent097f1e7625966673b881df63a241f755317b0bb9 (diff)
downloadllvm-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.cpp11
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);
+}