1010#include " clang/ASTMatchers/ASTMatchers.h"
1111#include " clang/Basic/Diagnostic.h"
1212#include " clang/Tooling/Tooling.h"
13- #include " llvm/ADT/SmallSet.h"
1413#include " gmock/gmock-matchers.h"
1514#include " gtest/gtest.h"
1615
@@ -33,24 +32,6 @@ template <typename InputNode>
3332using ResolveFnT = std::function<std::vector<const NamedDecl *>(
3433 const HeuristicResolver *, InputNode)>;
3534
36- std::string format_error (const clang::StoredDiagnostic &D) {
37- std::ostringstream Msg{};
38- if (D.getLevel () == DiagnosticsEngine::Level::Ignored)
39- Msg << " Ignored: " ;
40- if (D.getLevel () == DiagnosticsEngine::Level::Note)
41- Msg << " Note: " ;
42- if (D.getLevel () == DiagnosticsEngine::Level::Remark)
43- Msg << " Remark: " ;
44- if (D.getLevel () == DiagnosticsEngine::Level::Warning)
45- Msg << " Warning: " ;
46- if (D.getLevel () == DiagnosticsEngine::Level::Error)
47- Msg << " Error: " ;
48- if (D.getLevel () == DiagnosticsEngine::Level::Fatal)
49- Msg << " Fatal: " ;
50- Msg << D.getID () << " : " << D.getMessage ().str ();
51- return Msg.str ();
52- }
53-
5435// Test heuristic resolution on `Code` using the resolution procedure
5536// `ResolveFn`, which takes a `HeuristicResolver` and an input AST node of type
5637// `InputNode` and returns a `std::vector<const NamedDecl *>`.
@@ -61,10 +42,17 @@ template <typename InputNode, typename ParamT, typename InputMatcher,
6142 typename ... OutputMatchers>
6243void expectResolution (llvm::StringRef Code, ResolveFnT<ParamT> ResolveFn,
6344 const InputMatcher &IM, const OutputMatchers &...OMS) {
64- auto TU = tooling::buildASTFromCodeWithArgs (Code, {" -std=c++23" });
45+ auto TU = tooling::buildASTFromCodeWithArgs (
46+ Code, {" -std=c++23" }, " input.cc" , " clang-tool" ,
47+ std::make_shared<PCHContainerOperations>(),
48+ tooling::getClangStripDependencyFileAdjuster (),
49+ tooling::FileContentMappings (), nullptr , llvm::vfs::getRealFileSystem (),
50+ CaptureDiagsKind::All);
6551
6652 for (const auto &D : TU->storedDiagnostics ()) {
67- EXPECT_TRUE (D.getLevel () < DiagnosticsEngine::Error) << format_error (D);
53+ EXPECT_TRUE (D.getLevel () < DiagnosticsEngine::Error)
54+ << " Unexpected error diagnostic while building AST for test code: "
55+ << D.getMessage ();
6856 }
6957
7058 auto &Ctx = TU->getASTContext ();
0 commit comments