-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Add error check for HeuristicResolver #155561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,9 @@ | |
| #include "clang/Sema/HeuristicResolver.h" | ||
| #include "clang/ASTMatchers/ASTMatchFinder.h" | ||
| #include "clang/ASTMatchers/ASTMatchers.h" | ||
| #include "clang/Basic/Diagnostic.h" | ||
| #include "clang/Tooling/Tooling.h" | ||
| #include "llvm/ADT/SmallSet.h" | ||
| #include "gmock/gmock-matchers.h" | ||
| #include "gtest/gtest.h" | ||
|
|
||
|
|
@@ -31,6 +33,24 @@ template <typename InputNode> | |
| using ResolveFnT = std::function<std::vector<const NamedDecl *>( | ||
| const HeuristicResolver *, InputNode)>; | ||
|
|
||
| std::string format_error(const clang::StoredDiagnostic &D) { | ||
| std::ostringstream Msg{}; | ||
| if (D.getLevel() == DiagnosticsEngine::Level::Ignored) | ||
|
||
| Msg << "Ignored: "; | ||
| if (D.getLevel() == DiagnosticsEngine::Level::Note) | ||
| Msg << "Note: "; | ||
| if (D.getLevel() == DiagnosticsEngine::Level::Remark) | ||
| Msg << "Remark: "; | ||
| if (D.getLevel() == DiagnosticsEngine::Level::Warning) | ||
| Msg << "Warning: "; | ||
| if (D.getLevel() == DiagnosticsEngine::Level::Error) | ||
| Msg << "Error: "; | ||
| if (D.getLevel() == DiagnosticsEngine::Level::Fatal) | ||
| Msg << "Fatal: "; | ||
| Msg << D.getID() << ": " << D.getMessage().str(); | ||
| return Msg.str(); | ||
| } | ||
|
|
||
| // Test heuristic resolution on `Code` using the resolution procedure | ||
| // `ResolveFn`, which takes a `HeuristicResolver` and an input AST node of type | ||
| // `InputNode` and returns a `std::vector<const NamedDecl *>`. | ||
|
|
@@ -42,6 +62,11 @@ template <typename InputNode, typename ParamT, typename InputMatcher, | |
| void expectResolution(llvm::StringRef Code, ResolveFnT<ParamT> ResolveFn, | ||
| const InputMatcher &IM, const OutputMatchers &...OMS) { | ||
| auto TU = tooling::buildASTFromCodeWithArgs(Code, {"-std=c++23"}); | ||
|
||
|
|
||
| for (const auto &D : TU->storedDiagnostics()) { | ||
| EXPECT_TRUE(D.getLevel() < DiagnosticsEngine::Error) << format_error(D); | ||
| } | ||
|
|
||
| auto &Ctx = TU->getASTContext(); | ||
| auto InputMatches = match(IM, Ctx); | ||
| ASSERT_EQ(1u, InputMatches.size()); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
CaptureKindorCaptureDiags(Kinds, as in "more than one kind", does not make sense here)