From: Dmitri Gribenko Date: Fri, 31 Aug 2012 03:23:26 +0000 (+0000) Subject: DeclPrinter tests: simplify the code by using the new runToolOnCodeWithArgs X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=976f118dc5a2a89be29e6fd01e00f5a188b77847;p=clang DeclPrinter tests: simplify the code by using the new runToolOnCodeWithArgs function from Tooling. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162976 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/unittests/AST/DeclPrinterTest.cpp b/unittests/AST/DeclPrinterTest.cpp index 47afb0d4d1..0bb0272eb5 100644 --- a/unittests/AST/DeclPrinterTest.cpp +++ b/unittests/AST/DeclPrinterTest.cpp @@ -65,30 +65,9 @@ public: } }; -bool runToolOnCode(clang::FrontendAction *ToolAction, const Twine &Code, - ArrayRef ClangArgs) { - SmallString<16> FileNameStorage; - StringRef FileNameRef = "input.cc"; - - std::vector ArgVector; - ArgVector.push_back("clang-tool"); - ArgVector.push_back("-fsyntax-only"); - ArgVector.push_back(FileNameRef.data()); - for (unsigned i = 0, e = ClangArgs.size(); i != e; ++i) - ArgVector.push_back(ClangArgs[i]); - - FileManager Files((FileSystemOptions())); - ToolInvocation Invocation(ArgVector, ToolAction, &Files); - - SmallString<1024> CodeStorage; - Invocation.mapVirtualFile(FileNameRef, - Code.toNullTerminatedStringRef(CodeStorage)); - return Invocation.run(); -} - ::testing::AssertionResult PrintedDeclMatches( StringRef Code, - ArrayRef ClangArgs, + const std::vector &Args, const DeclarationMatcher &NodeMatch, StringRef ExpectedPrinted) { PrintMatch Printer; @@ -96,7 +75,7 @@ bool runToolOnCode(clang::FrontendAction *ToolAction, const Twine &Code, Finder.addMatcher(NodeMatch, &Printer); OwningPtr Factory(newFrontendActionFactory(&Finder)); - if (!runToolOnCode(Factory->create(), Code, ClangArgs)) + if (!runToolOnCodeWithArgs(Factory->create(), Code, Args)) return testing::AssertionFailure() << "Parsing error in \"" << Code << "\""; if (Printer.getNumFoundDecls() == 0) @@ -119,8 +98,9 @@ bool runToolOnCode(clang::FrontendAction *ToolAction, const Twine &Code, ::testing::AssertionResult PrintedDeclCXX98Matches(StringRef Code, StringRef DeclName, StringRef ExpectedPrinted) { + std::vector Args(1, "-std=c++98"); return PrintedDeclMatches(Code, - ArrayRef("-std=c++98"), + Args, namedDecl(hasName(DeclName)).bind("id"), ExpectedPrinted); } @@ -129,8 +109,9 @@ bool runToolOnCode(clang::FrontendAction *ToolAction, const Twine &Code, StringRef Code, const DeclarationMatcher &NodeMatch, StringRef ExpectedPrinted) { + std::vector Args(1, "-std=c++98"); return PrintedDeclMatches(Code, - ArrayRef("-std=c++98"), + Args, NodeMatch, ExpectedPrinted); } @@ -138,8 +119,9 @@ bool runToolOnCode(clang::FrontendAction *ToolAction, const Twine &Code, ::testing::AssertionResult PrintedDeclCXX11Matches(StringRef Code, StringRef DeclName, StringRef ExpectedPrinted) { + std::vector Args(1, "-std=c++11"); return PrintedDeclMatches(Code, - ArrayRef("-std=c++11"), + Args, namedDecl(hasName(DeclName)).bind("id"), ExpectedPrinted); } @@ -148,8 +130,9 @@ bool runToolOnCode(clang::FrontendAction *ToolAction, const Twine &Code, StringRef Code, const DeclarationMatcher &NodeMatch, StringRef ExpectedPrinted) { + std::vector Args(1, "-std=c++11"); return PrintedDeclMatches(Code, - ArrayRef("-std=c++11"), + Args, NodeMatch, ExpectedPrinted); }