[VFS] Switch clang-tidy tests to use an in-memory fs.

Again, this is both cleaner and completely removes any depedency on the
host file system.

llvm-svn: 249526
This commit is contained in:
Benjamin Kramer
2015-10-07 08:35:23 +00:00
parent d5e0b58ef2
commit ac8517c2bf

View File

@@ -90,17 +90,21 @@ runCheckOnCode(StringRef Code, std::vector<ClangTidyError> *Errors = nullptr,
ArgCXX11.push_back(Filename.str());
ast_matchers::MatchFinder Finder;
llvm::IntrusiveRefCntPtr<vfs::InMemoryFileSystem> InMemoryFileSystem(
new vfs::InMemoryFileSystem);
llvm::IntrusiveRefCntPtr<FileManager> Files(
new FileManager(FileSystemOptions()));
new FileManager(FileSystemOptions(), InMemoryFileSystem));
SmallVector<std::unique_ptr<ClangTidyCheck>, 1> Checks;
CheckFactory<CheckList...>::createChecks(&Context, Checks);
tooling::ToolInvocation Invocation(
ArgCXX11, new TestClangTidyAction(Checks, Finder, Context), Files.get());
Invocation.mapVirtualFile(Filename.str(), Code);
InMemoryFileSystem->addFile(Filename, 0,
llvm::MemoryBuffer::getMemBuffer(Code));
for (const auto &FileContent : PathsToContent) {
Invocation.mapVirtualFile(Twine("include/" + FileContent.first).str(),
FileContent.second);
InMemoryFileSystem->addFile(
Twine("include/") + FileContent.first, 0,
llvm::MemoryBuffer::getMemBuffer(FileContent.second));
}
Invocation.setDiagnosticConsumer(&DiagConsumer);
if (!Invocation.run()) {