diff options
author | dim <dim@FreeBSD.org> | 2014-11-24 09:15:30 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2014-11-24 09:15:30 +0000 |
commit | 173a4f43a911175643bda81ee675e8d9269056ea (patch) | |
tree | 47df2c12b57214af6c31e47404b005675b8b7ffc /unittests/Tooling/ToolingTest.cpp | |
parent | 88f7a7d5251a2d813460274c92decc143a11569b (diff) | |
download | FreeBSD-src-173a4f43a911175643bda81ee675e8d9269056ea.zip FreeBSD-src-173a4f43a911175643bda81ee675e8d9269056ea.tar.gz |
Vendor import of clang RELEASE_350/final tag r216957 (effectively, 3.5.0 release):
https://llvm.org/svn/llvm-project/cfe/tags/RELEASE_350/final@216957
Diffstat (limited to 'unittests/Tooling/ToolingTest.cpp')
-rw-r--r-- | unittests/Tooling/ToolingTest.cpp | 74 |
1 files changed, 45 insertions, 29 deletions
diff --git a/unittests/Tooling/ToolingTest.cpp b/unittests/Tooling/ToolingTest.cpp index 2c4a8a7..9aede04 100644 --- a/unittests/Tooling/ToolingTest.cpp +++ b/unittests/Tooling/ToolingTest.cpp @@ -16,8 +16,9 @@ #include "clang/Frontend/FrontendActions.h" #include "clang/Tooling/CompilationDatabase.h" #include "clang/Tooling/Tooling.h" -#include "gtest/gtest.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/Config/llvm-config.h" +#include "gtest/gtest.h" #include <string> namespace clang { @@ -60,12 +61,7 @@ TEST(runToolOnCode, FindsNoTopLevelDeclOnEmptyCode) { bool FoundTopLevelDecl = false; EXPECT_TRUE(runToolOnCode( new TestAction(new FindTopLevelDeclConsumer(&FoundTopLevelDecl)), "")); -#if !defined(_MSC_VER) EXPECT_FALSE(FoundTopLevelDecl); -#else - // FIXME: LangOpts.MicrosoftExt appends "class type_info;" - EXPECT_TRUE(FoundTopLevelDecl); -#endif } namespace { @@ -112,34 +108,34 @@ TEST(runToolOnCode, FindsClassDecl) { } TEST(buildASTFromCode, FindsClassDecl) { - OwningPtr<ASTUnit> AST(buildASTFromCode("class X;")); + std::unique_ptr<ASTUnit> AST = buildASTFromCode("class X;"); ASSERT_TRUE(AST.get()); EXPECT_TRUE(FindClassDeclX(AST.get())); - AST.reset(buildASTFromCode("class Y;")); + AST = buildASTFromCode("class Y;"); ASSERT_TRUE(AST.get()); EXPECT_FALSE(FindClassDeclX(AST.get())); } TEST(newFrontendActionFactory, CreatesFrontendActionFactoryFromType) { - OwningPtr<FrontendActionFactory> Factory( + std::unique_ptr<FrontendActionFactory> Factory( newFrontendActionFactory<SyntaxOnlyAction>()); - OwningPtr<FrontendAction> Action(Factory->create()); - EXPECT_TRUE(Action.get() != NULL); + std::unique_ptr<FrontendAction> Action(Factory->create()); + EXPECT_TRUE(Action.get() != nullptr); } struct IndependentFrontendActionCreator { ASTConsumer *newASTConsumer() { - return new FindTopLevelDeclConsumer(NULL); + return new FindTopLevelDeclConsumer(nullptr); } }; TEST(newFrontendActionFactory, CreatesFrontendActionFactoryFromFactoryType) { IndependentFrontendActionCreator Creator; - OwningPtr<FrontendActionFactory> Factory( + std::unique_ptr<FrontendActionFactory> Factory( newFrontendActionFactory(&Creator)); - OwningPtr<FrontendAction> Action(Factory->create()); - EXPECT_TRUE(Action.get() != NULL); + std::unique_ptr<FrontendAction> Action(Factory->create()); + EXPECT_TRUE(Action.get() != nullptr); } TEST(ToolInvocation, TestMapVirtualFile) { @@ -151,7 +147,7 @@ TEST(ToolInvocation, TestMapVirtualFile) { Args.push_back("-fsyntax-only"); Args.push_back("test.cpp"); clang::tooling::ToolInvocation Invocation(Args, new SyntaxOnlyAction, - Files.getPtr()); + Files.get()); Invocation.mapVirtualFile("test.cpp", "#include <abc>\n"); Invocation.mapVirtualFile("def/abc", "\n"); EXPECT_TRUE(Invocation.run()); @@ -170,7 +166,7 @@ TEST(ToolInvocation, TestVirtualModulesCompilation) { Args.push_back("-fsyntax-only"); Args.push_back("test.cpp"); clang::tooling::ToolInvocation Invocation(Args, new SyntaxOnlyAction, - Files.getPtr()); + Files.get()); Invocation.mapVirtualFile("test.cpp", "#include <abc>\n"); Invocation.mapVirtualFile("def/abc", "\n"); // Add a module.map file in the include directory of our header, so we trigger @@ -182,7 +178,7 @@ TEST(ToolInvocation, TestVirtualModulesCompilation) { struct VerifyEndCallback : public SourceFileCallbacks { VerifyEndCallback() : BeginCalled(0), EndCalled(0), Matched(false) {} virtual bool handleBeginSource(CompilerInstance &CI, - StringRef Filename) LLVM_OVERRIDE { + StringRef Filename) override { ++BeginCalled; return true; } @@ -197,7 +193,7 @@ struct VerifyEndCallback : public SourceFileCallbacks { bool Matched; }; -#if !defined(_WIN32) +#if !defined(LLVM_ON_WIN32) TEST(newFrontendActionFactory, InjectsSourceFileCallbacks) { VerifyEndCallback EndCallback; @@ -210,7 +206,9 @@ TEST(newFrontendActionFactory, InjectsSourceFileCallbacks) { Tool.mapVirtualFile("/a.cc", "void a() {}"); Tool.mapVirtualFile("/b.cc", "void b() {}"); - Tool.run(newFrontendActionFactory(&EndCallback, &EndCallback)); + std::unique_ptr<FrontendActionFactory> Action( + newFrontendActionFactory(&EndCallback, &EndCallback)); + Tool.run(Action.get()); EXPECT_TRUE(EndCallback.Matched); EXPECT_EQ(2u, EndCallback.BeginCalled); @@ -241,6 +239,21 @@ TEST(runToolOnCode, TestSkipFunctionBody) { "int skipMeNot() { an_error_here }")); } +TEST(runToolOnCodeWithArgs, TestNoDepFile) { + llvm::SmallString<32> DepFilePath; + ASSERT_FALSE( + llvm::sys::fs::createTemporaryFile("depfile", "d", DepFilePath)); + std::vector<std::string> Args; + Args.push_back("-MMD"); + Args.push_back("-MT"); + Args.push_back(DepFilePath.str()); + Args.push_back("-MF"); + Args.push_back(DepFilePath.str()); + EXPECT_TRUE(runToolOnCodeWithArgs(new SkipBodyAction, "", Args)); + EXPECT_FALSE(llvm::sys::fs::exists(DepFilePath.str())); + EXPECT_FALSE(llvm::sys::fs::remove(DepFilePath.str())); +} + struct CheckSyntaxOnlyAdjuster: public ArgumentsAdjuster { bool &Found; bool &Ran; @@ -248,7 +261,7 @@ struct CheckSyntaxOnlyAdjuster: public ArgumentsAdjuster { CheckSyntaxOnlyAdjuster(bool &Found, bool &Ran) : Found(Found), Ran(Ran) { } virtual CommandLineArguments - Adjust(const CommandLineArguments &Args) LLVM_OVERRIDE { + Adjust(const CommandLineArguments &Args) override { Ran = true; for (unsigned I = 0, E = Args.size(); I != E; ++I) { if (Args[I] == "-fsyntax-only") { @@ -266,10 +279,13 @@ TEST(ClangToolTest, ArgumentAdjusters) { ClangTool Tool(Compilations, std::vector<std::string>(1, "/a.cc")); Tool.mapVirtualFile("/a.cc", "void a() {}"); + std::unique_ptr<FrontendActionFactory> Action( + newFrontendActionFactory<SyntaxOnlyAction>()); + bool Found = false; bool Ran = false; Tool.appendArgumentsAdjuster(new CheckSyntaxOnlyAdjuster(Found, Ran)); - Tool.run(newFrontendActionFactory<SyntaxOnlyAction>()); + Tool.run(Action.get()); EXPECT_TRUE(Ran); EXPECT_TRUE(Found); @@ -277,12 +293,12 @@ TEST(ClangToolTest, ArgumentAdjusters) { Tool.clearArgumentsAdjusters(); Tool.appendArgumentsAdjuster(new CheckSyntaxOnlyAdjuster(Found, Ran)); Tool.appendArgumentsAdjuster(new ClangSyntaxOnlyAdjuster()); - Tool.run(newFrontendActionFactory<SyntaxOnlyAction>()); + Tool.run(Action.get()); EXPECT_TRUE(Ran); EXPECT_FALSE(Found); } -#ifndef _WIN32 +#ifndef LLVM_ON_WIN32 TEST(ClangToolTest, BuildASTs) { FixedCompilationDatabase Compilations("/", std::vector<std::string>()); @@ -294,11 +310,9 @@ TEST(ClangToolTest, BuildASTs) { Tool.mapVirtualFile("/a.cc", "void a() {}"); Tool.mapVirtualFile("/b.cc", "void b() {}"); - std::vector<ASTUnit *> ASTs; + std::vector<std::unique_ptr<ASTUnit>> ASTs; EXPECT_EQ(0, Tool.buildASTs(ASTs)); EXPECT_EQ(2u, ASTs.size()); - - llvm::DeleteContainerPointers(ASTs); } struct TestDiagnosticConsumer : public DiagnosticConsumer { @@ -316,7 +330,9 @@ TEST(ClangToolTest, InjectDiagnosticConsumer) { Tool.mapVirtualFile("/a.cc", "int x = undeclared;"); TestDiagnosticConsumer Consumer; Tool.setDiagnosticConsumer(&Consumer); - Tool.run(newFrontendActionFactory<SyntaxOnlyAction>()); + std::unique_ptr<FrontendActionFactory> Action( + newFrontendActionFactory<SyntaxOnlyAction>()); + Tool.run(Action.get()); EXPECT_EQ(1u, Consumer.NumDiagnosticsSeen); } @@ -326,7 +342,7 @@ TEST(ClangToolTest, InjectDiagnosticConsumerInBuildASTs) { Tool.mapVirtualFile("/a.cc", "int x = undeclared;"); TestDiagnosticConsumer Consumer; Tool.setDiagnosticConsumer(&Consumer); - std::vector<ASTUnit*> ASTs; + std::vector<std::unique_ptr<ASTUnit>> ASTs; Tool.buildASTs(ASTs); EXPECT_EQ(1u, ASTs.size()); EXPECT_EQ(1u, Consumer.NumDiagnosticsSeen); |