diff options
author | Nathan Ridge <zeratul976@hotmail.com> | 2021-07-06 01:40:24 -0400 |
---|---|---|
committer | Nathan Ridge <zeratul976@hotmail.com> | 2021-07-13 01:48:30 -0400 |
commit | 20176bc7dd3f431db4c3d59b51a9f53d52190c82 (patch) | |
tree | 0736f79c7d02935c51f81ff33e546bad587c32d7 /clang/unittests/AST/NamedDeclPrinterTest.cpp | |
parent | c41e67f3f11b65f77d288c8aa5324a8b71debfb3 (diff) | |
download | llvm-20176bc7dd3f431db4c3d59b51a9f53d52190c82.zip llvm-20176bc7dd3f431db4c3d59b51a9f53d52190c82.tar.gz llvm-20176bc7dd3f431db4c3d59b51a9f53d52190c82.tar.bz2 |
[clang] Refactor AST printing tests to share more infrastructure
Differential Revision: https://reviews.llvm.org/D105457
Diffstat (limited to 'clang/unittests/AST/NamedDeclPrinterTest.cpp')
-rw-r--r-- | clang/unittests/AST/NamedDeclPrinterTest.cpp | 31 |
1 files changed, 6 insertions, 25 deletions
diff --git a/clang/unittests/AST/NamedDeclPrinterTest.cpp b/clang/unittests/AST/NamedDeclPrinterTest.cpp index 1042312..cd83372 100644 --- a/clang/unittests/AST/NamedDeclPrinterTest.cpp +++ b/clang/unittests/AST/NamedDeclPrinterTest.cpp @@ -15,6 +15,7 @@ // //===----------------------------------------------------------------------===// +#include "ASTPrint.h" #include "clang/AST/ASTContext.h" #include "clang/AST/Decl.h" #include "clang/AST/PrettyPrinter.h" @@ -66,31 +67,11 @@ public: const DeclarationMatcher &NodeMatch, StringRef ExpectedPrinted, StringRef FileName, std::function<void(llvm::raw_ostream &, const NamedDecl *)> Print) { - PrintMatch Printer(std::move(Print)); - MatchFinder Finder; - Finder.addMatcher(NodeMatch, &Printer); - std::unique_ptr<FrontendActionFactory> Factory = - newFrontendActionFactory(&Finder); - - if (!runToolOnCodeWithArgs(Factory->create(), Code, Args, FileName)) - return testing::AssertionFailure() - << "Parsing error in \"" << Code.str() << "\""; - - if (Printer.getNumFoundDecls() == 0) - return testing::AssertionFailure() - << "Matcher didn't find any named declarations"; - - if (Printer.getNumFoundDecls() > 1) - return testing::AssertionFailure() - << "Matcher should match only one named declaration " - "(found " << Printer.getNumFoundDecls() << ")"; - - if (Printer.getPrinted() != ExpectedPrinted) - return ::testing::AssertionFailure() - << "Expected \"" << ExpectedPrinted.str() << "\", " - "got \"" << Printer.getPrinted().str() << "\""; - - return ::testing::AssertionSuccess(); + return PrintedNodeMatches<NamedDecl>( + Code, Args, NodeMatch, ExpectedPrinted, FileName, + [Print](llvm::raw_ostream &Out, const ASTContext *Context, + const NamedDecl *ND, + PrintingPolicyAdjuster PolicyAdjuster) { Print(Out, ND); }); } ::testing::AssertionResult |