88#include " clang/Sema/HeuristicResolver.h"
99#include " clang/ASTMatchers/ASTMatchFinder.h"
1010#include " clang/ASTMatchers/ASTMatchers.h"
11+ #include " clang/Basic/Diagnostic.h"
1112#include " clang/Tooling/Tooling.h"
13+ #include " llvm/ADT/SmallSet.h"
1214#include " gmock/gmock-matchers.h"
1315#include " gtest/gtest.h"
1416
@@ -31,6 +33,24 @@ template <typename InputNode>
3133using ResolveFnT = std::function<std::vector<const NamedDecl *>(
3234 const HeuristicResolver *, InputNode)>;
3335
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+
3454// Test heuristic resolution on `Code` using the resolution procedure
3555// `ResolveFn`, which takes a `HeuristicResolver` and an input AST node of type
3656// `InputNode` and returns a `std::vector<const NamedDecl *>`.
@@ -41,7 +61,16 @@ template <typename InputNode, typename ParamT, typename InputMatcher,
4161 typename ... OutputMatchers>
4262void expectResolution (llvm::StringRef Code, ResolveFnT<ParamT> ResolveFn,
4363 const InputMatcher &IM, const OutputMatchers &...OMS) {
64+ llvm::SmallSet<unsigned int , 16 > IgnoredDiagnostics{};
4465 auto TU = tooling::buildASTFromCodeWithArgs (Code, {" -std=c++23" });
66+
67+ for (auto D = TU->stored_diag_begin (), DEnd = TU->stored_diag_end ();
68+ D != DEnd; ++D) {
69+ EXPECT_TRUE (D->getLevel () < DiagnosticsEngine::Warning ||
70+ IgnoredDiagnostics.contains (D->getID ()))
71+ << format_error (D);
72+ }
73+
4574 auto &Ctx = TU->getASTContext ();
4675 auto InputMatches = match (IM, Ctx);
4776 ASSERT_EQ (1u , InputMatches.size ());
0 commit comments