diff options
author | Dmitri Gribenko <gribozavr@gmail.com> | 2012-08-31 03:23:26 +0000 |
---|---|---|
committer | Dmitri Gribenko <gribozavr@gmail.com> | 2012-08-31 03:23:26 +0000 |
commit | 976f118dc5a2a89be29e6fd01e00f5a188b77847 (patch) | |
tree | 96a235c2fff22119ba2df87ff147c1ba981bcdb9 /unittests/AST/DeclPrinterTest.cpp | |
parent | dfccbd95d81a74cd322b77ac31c64589a528ef92 (diff) |
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
Diffstat (limited to 'unittests/AST/DeclPrinterTest.cpp')
-rw-r--r-- | unittests/AST/DeclPrinterTest.cpp | 37 |
1 files changed, 10 insertions, 27 deletions
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<const char *> ClangArgs) { - SmallString<16> FileNameStorage; - StringRef FileNameRef = "input.cc"; - - std::vector<std::string> 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<const char *> ClangArgs, + const std::vector<std::string> &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<FrontendActionFactory> 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<std::string> Args(1, "-std=c++98"); return PrintedDeclMatches(Code, - ArrayRef<const char *>("-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<std::string> Args(1, "-std=c++98"); return PrintedDeclMatches(Code, - ArrayRef<const char *>("-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<std::string> Args(1, "-std=c++11"); return PrintedDeclMatches(Code, - ArrayRef<const char *>("-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<std::string> Args(1, "-std=c++11"); return PrintedDeclMatches(Code, - ArrayRef<const char *>("-std=c++11"), + Args, NodeMatch, ExpectedPrinted); } |