diff options
author | Roman Lebedev <lebedev.ri@gmail.com> | 2018-02-27 15:19:20 +0000 |
---|---|---|
committer | Roman Lebedev <lebedev.ri@gmail.com> | 2018-02-27 15:19:20 +0000 |
commit | 6017bf4f315f9a49a2512cef0d640197172659b3 (patch) | |
tree | f19b88a8c5de0f7316a21adc5ddbd725b9416845 /clang/unittests/Tooling/ToolingTest.cpp | |
parent | 46045364b291c7b674a8c8db53a370c1f518158e (diff) | |
download | bcm5719-llvm-6017bf4f315f9a49a2512cef0d640197172659b3.tar.gz bcm5719-llvm-6017bf4f315f9a49a2512cef0d640197172659b3.zip |
[Tooling] [0/1] Refactor FrontendActionFactory::create() to return std::unique_ptr<>
Summary:
Noticed during review of D41102.
I'm not sure whether there are any principal reasons why it returns raw owning pointer,
or it is just a old code that was not updated post-C++11.
I'm not too sure what testing i should do, because `check-all` is not error clean here for some reason,
but it does not //appear// asif those failures are related to these changes.
This is clang part.
Clang-tools-extra part is D43780.
Reviewers: klimek, bkramer, alexfh, pcc
Reviewed By: alexfh
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D43779
llvm-svn: 326201
Diffstat (limited to 'clang/unittests/Tooling/ToolingTest.cpp')
-rw-r--r-- | clang/unittests/Tooling/ToolingTest.cpp | 111 |
1 files changed, 59 insertions, 52 deletions
diff --git a/clang/unittests/Tooling/ToolingTest.cpp b/clang/unittests/Tooling/ToolingTest.cpp index 6dd0e53c4dd..a4fb579038b 100644 --- a/clang/unittests/Tooling/ToolingTest.cpp +++ b/clang/unittests/Tooling/ToolingTest.cpp @@ -64,10 +64,10 @@ class FindTopLevelDeclConsumer : public clang::ASTConsumer { TEST(runToolOnCode, FindsNoTopLevelDeclOnEmptyCode) { bool FoundTopLevelDecl = false; - EXPECT_TRUE( - runToolOnCode(new TestAction(llvm::make_unique<FindTopLevelDeclConsumer>( - &FoundTopLevelDecl)), - "")); + EXPECT_TRUE(runToolOnCode( + llvm::make_unique<TestAction>( + llvm::make_unique<FindTopLevelDeclConsumer>(&FoundTopLevelDecl)), + "")); EXPECT_FALSE(FoundTopLevelDecl); } @@ -104,17 +104,17 @@ bool FindClassDeclX(ASTUnit *AST) { TEST(runToolOnCode, FindsClassDecl) { bool FoundClassDeclX = false; - EXPECT_TRUE( - runToolOnCode(new TestAction(llvm::make_unique<FindClassDeclXConsumer>( - &FoundClassDeclX)), - "class X;")); + EXPECT_TRUE(runToolOnCode( + llvm::make_unique<TestAction>( + llvm::make_unique<FindClassDeclXConsumer>(&FoundClassDeclX)), + "class X;")); EXPECT_TRUE(FoundClassDeclX); FoundClassDeclX = false; - EXPECT_TRUE( - runToolOnCode(new TestAction(llvm::make_unique<FindClassDeclXConsumer>( - &FoundClassDeclX)), - "class Y;")); + EXPECT_TRUE(runToolOnCode( + llvm::make_unique<TestAction>( + llvm::make_unique<FindClassDeclXConsumer>(&FoundClassDeclX)), + "class Y;")); EXPECT_FALSE(FoundClassDeclX); } @@ -162,8 +162,8 @@ TEST(ToolInvocation, TestMapVirtualFile) { Args.push_back("-Idef"); Args.push_back("-fsyntax-only"); Args.push_back("test.cpp"); - clang::tooling::ToolInvocation Invocation(Args, new SyntaxOnlyAction, - Files.get()); + clang::tooling::ToolInvocation Invocation( + Args, llvm::make_unique<SyntaxOnlyAction>(), Files.get()); InMemoryFileSystem->addFile( "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("#include <abc>\n")); InMemoryFileSystem->addFile("def/abc", 0, @@ -188,8 +188,8 @@ TEST(ToolInvocation, TestVirtualModulesCompilation) { Args.push_back("-Idef"); Args.push_back("-fsyntax-only"); Args.push_back("test.cpp"); - clang::tooling::ToolInvocation Invocation(Args, new SyntaxOnlyAction, - Files.get()); + clang::tooling::ToolInvocation Invocation( + Args, llvm::make_unique<SyntaxOnlyAction>(), Files.get()); InMemoryFileSystem->addFile( "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("#include <abc>\n")); InMemoryFileSystem->addFile("def/abc", 0, @@ -259,61 +259,64 @@ TEST(runToolOnCode, TestSkipFunctionBody) { std::vector<std::string> Args = {"-std=c++11"}; std::vector<std::string> Args2 = {"-fno-delayed-template-parsing"}; - EXPECT_TRUE(runToolOnCode(new SkipBodyAction, + EXPECT_TRUE(runToolOnCode(llvm::make_unique<SkipBodyAction>(), "int skipMe() { an_error_here }")); - EXPECT_FALSE(runToolOnCode(new SkipBodyAction, + EXPECT_FALSE(runToolOnCode(llvm::make_unique<SkipBodyAction>(), "int skipMeNot() { an_error_here }")); // Test constructors with initializers EXPECT_TRUE(runToolOnCodeWithArgs( - new SkipBodyAction, + llvm::make_unique<SkipBodyAction>(), "struct skipMe { skipMe() : an_error() { more error } };", Args)); EXPECT_TRUE(runToolOnCodeWithArgs( - new SkipBodyAction, "struct skipMe { skipMe(); };" - "skipMe::skipMe() : an_error([](){;}) { more error }", + llvm::make_unique<SkipBodyAction>(), + "struct skipMe { skipMe(); };" + "skipMe::skipMe() : an_error([](){;}) { more error }", Args)); EXPECT_TRUE(runToolOnCodeWithArgs( - new SkipBodyAction, "struct skipMe { skipMe(); };" - "skipMe::skipMe() : an_error{[](){;}} { more error }", + llvm::make_unique<SkipBodyAction>(), + "struct skipMe { skipMe(); };" + "skipMe::skipMe() : an_error{[](){;}} { more error }", Args)); EXPECT_TRUE(runToolOnCodeWithArgs( - new SkipBodyAction, + llvm::make_unique<SkipBodyAction>(), "struct skipMe { skipMe(); };" "skipMe::skipMe() : a<b<c>(e)>>(), f{}, g() { error }", Args)); EXPECT_TRUE(runToolOnCodeWithArgs( - new SkipBodyAction, "struct skipMe { skipMe() : bases()... { error } };", - Args)); + llvm::make_unique<SkipBodyAction>(), + "struct skipMe { skipMe() : bases()... { error } };", Args)); EXPECT_FALSE(runToolOnCodeWithArgs( - new SkipBodyAction, "struct skipMeNot { skipMeNot() : an_error() { } };", - Args)); - EXPECT_FALSE(runToolOnCodeWithArgs(new SkipBodyAction, + llvm::make_unique<SkipBodyAction>(), + "struct skipMeNot { skipMeNot() : an_error() { } };", Args)); + EXPECT_FALSE(runToolOnCodeWithArgs(llvm::make_unique<SkipBodyAction>(), "struct skipMeNot { skipMeNot(); };" "skipMeNot::skipMeNot() : an_error() { }", Args)); // Try/catch EXPECT_TRUE(runToolOnCode( - new SkipBodyAction, + llvm::make_unique<SkipBodyAction>(), "void skipMe() try { an_error() } catch(error) { error };")); EXPECT_TRUE(runToolOnCode( - new SkipBodyAction, + llvm::make_unique<SkipBodyAction>(), "struct S { void skipMe() try { an_error() } catch(error) { error } };")); EXPECT_TRUE( - runToolOnCode(new SkipBodyAction, + runToolOnCode(llvm::make_unique<SkipBodyAction>(), "void skipMe() try { an_error() } catch(error) { error; }" "catch(error) { error } catch (error) { }")); EXPECT_FALSE(runToolOnCode( - new SkipBodyAction, + llvm::make_unique<SkipBodyAction>(), "void skipMe() try something;")); // don't crash while parsing // Template - EXPECT_TRUE(runToolOnCode( - new SkipBodyAction, "template<typename T> int skipMe() { an_error_here }" - "int x = skipMe<int>();")); + EXPECT_TRUE( + runToolOnCode(llvm::make_unique<SkipBodyAction>(), + "template<typename T> int skipMe() { an_error_here }" + "int x = skipMe<int>();")); EXPECT_FALSE(runToolOnCodeWithArgs( - new SkipBodyAction, + llvm::make_unique<SkipBodyAction>(), "template<typename T> int skipMeNot() { an_error_here }", Args2)); } @@ -327,7 +330,8 @@ TEST(runToolOnCodeWithArgs, TestNoDepFile) { Args.push_back(DepFilePath.str()); Args.push_back("-MF"); Args.push_back(DepFilePath.str()); - EXPECT_TRUE(runToolOnCodeWithArgs(new SkipBodyAction, "", Args)); + EXPECT_TRUE( + runToolOnCodeWithArgs(llvm::make_unique<SkipBodyAction>(), "", Args)); EXPECT_FALSE(llvm::sys::fs::exists(DepFilePath.str())); EXPECT_FALSE(llvm::sys::fs::remove(DepFilePath.str())); } @@ -351,23 +355,26 @@ private: TEST(runToolOnCodeWithArgs, DiagnosticsColor) { - EXPECT_TRUE(runToolOnCodeWithArgs(new CheckColoredDiagnosticsAction(true), "", - {"-fcolor-diagnostics"})); - EXPECT_TRUE(runToolOnCodeWithArgs(new CheckColoredDiagnosticsAction(false), - "", {"-fno-color-diagnostics"})); - EXPECT_TRUE( - runToolOnCodeWithArgs(new CheckColoredDiagnosticsAction(true), "", - {"-fno-color-diagnostics", "-fcolor-diagnostics"})); - EXPECT_TRUE( - runToolOnCodeWithArgs(new CheckColoredDiagnosticsAction(false), "", - {"-fcolor-diagnostics", "-fno-color-diagnostics"})); EXPECT_TRUE(runToolOnCodeWithArgs( - new CheckColoredDiagnosticsAction(true), "", + llvm::make_unique<CheckColoredDiagnosticsAction>(true), "", + {"-fcolor-diagnostics"})); + EXPECT_TRUE(runToolOnCodeWithArgs( + llvm::make_unique<CheckColoredDiagnosticsAction>(false), "", + {"-fno-color-diagnostics"})); + EXPECT_TRUE(runToolOnCodeWithArgs( + llvm::make_unique<CheckColoredDiagnosticsAction>(true), "", + {"-fno-color-diagnostics", "-fcolor-diagnostics"})); + EXPECT_TRUE(runToolOnCodeWithArgs( + llvm::make_unique<CheckColoredDiagnosticsAction>(false), "", + {"-fcolor-diagnostics", "-fno-color-diagnostics"})); + EXPECT_TRUE(runToolOnCodeWithArgs( + llvm::make_unique<CheckColoredDiagnosticsAction>(true), "", {"-fno-color-diagnostics", "-fdiagnostics-color=always"})); // Check that this test would fail if ShowColors is not what it should. - EXPECT_FALSE(runToolOnCodeWithArgs(new CheckColoredDiagnosticsAction(false), - "", {"-fcolor-diagnostics"})); + EXPECT_FALSE(runToolOnCodeWithArgs( + llvm::make_unique<CheckColoredDiagnosticsAction>(false), "", + {"-fcolor-diagnostics"})); } TEST(ClangToolTest, ArgumentAdjusters) { @@ -603,7 +610,7 @@ TEST(runToolOnCode, TestResetDiagnostics) { // Should not crash EXPECT_FALSE( - runToolOnCode(new ResetDiagnosticAction, + runToolOnCode(llvm::make_unique<ResetDiagnosticAction>(), "struct Foo { Foo(int); ~Foo(); struct Fwd _fwd; };" "void func() { long x; Foo f(x); }")); } |