diff options
Diffstat (limited to 'clang/unittests/Tooling/ToolingTest.cpp')
-rw-r--r-- | clang/unittests/Tooling/ToolingTest.cpp | 96 |
1 files changed, 49 insertions, 47 deletions
diff --git a/clang/unittests/Tooling/ToolingTest.cpp b/clang/unittests/Tooling/ToolingTest.cpp index 447b9973e4a..c22d0bdca48 100644 --- a/clang/unittests/Tooling/ToolingTest.cpp +++ b/clang/unittests/Tooling/ToolingTest.cpp @@ -62,10 +62,10 @@ class FindTopLevelDeclConsumer : public clang::ASTConsumer { TEST(runToolOnCode, FindsNoTopLevelDeclOnEmptyCode) { bool FoundTopLevelDecl = false; - EXPECT_TRUE( - runToolOnCode(new TestAction(std::make_unique<FindTopLevelDeclConsumer>( - &FoundTopLevelDecl)), - "")); + EXPECT_TRUE(runToolOnCode( + std::make_unique<TestAction>( + std::make_unique<FindTopLevelDeclConsumer>(&FoundTopLevelDecl)), + "")); EXPECT_FALSE(FoundTopLevelDecl); } @@ -102,17 +102,17 @@ bool FindClassDeclX(ASTUnit *AST) { TEST(runToolOnCode, FindsClassDecl) { bool FoundClassDeclX = false; - EXPECT_TRUE( - runToolOnCode(new TestAction(std::make_unique<FindClassDeclXConsumer>( - &FoundClassDeclX)), - "class X;")); + EXPECT_TRUE(runToolOnCode( + std::make_unique<TestAction>( + std::make_unique<FindClassDeclXConsumer>(&FoundClassDeclX)), + "class X;")); EXPECT_TRUE(FoundClassDeclX); FoundClassDeclX = false; - EXPECT_TRUE( - runToolOnCode(new TestAction(std::make_unique<FindClassDeclXConsumer>( - &FoundClassDeclX)), - "class Y;")); + EXPECT_TRUE(runToolOnCode( + std::make_unique<TestAction>( + std::make_unique<FindClassDeclXConsumer>(&FoundClassDeclX)), + "class Y;")); EXPECT_FALSE(FoundClassDeclX); } @@ -160,8 +160,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, std::make_unique<SyntaxOnlyAction>(), Files.get()); InMemoryFileSystem->addFile( "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("#include <abc>\n")); InMemoryFileSystem->addFile("def/abc", 0, @@ -186,8 +186,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, std::make_unique<SyntaxOnlyAction>(), Files.get()); InMemoryFileSystem->addFile( "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("#include <abc>\n")); InMemoryFileSystem->addFile("def/abc", 0, @@ -257,61 +257,61 @@ 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(std::make_unique<SkipBodyAction>(), "int skipMe() { an_error_here }")); - EXPECT_FALSE(runToolOnCode(new SkipBodyAction, + EXPECT_FALSE(runToolOnCode(std::make_unique<SkipBodyAction>(), "int skipMeNot() { an_error_here }")); // Test constructors with initializers EXPECT_TRUE(runToolOnCodeWithArgs( - new SkipBodyAction, + std::make_unique<SkipBodyAction>(), "struct skipMe { skipMe() : an_error() { more error } };", Args)); EXPECT_TRUE(runToolOnCodeWithArgs( - new SkipBodyAction, "struct skipMe { skipMe(); };" + std::make_unique<SkipBodyAction>(), "struct skipMe { skipMe(); };" "skipMe::skipMe() : an_error([](){;}) { more error }", Args)); EXPECT_TRUE(runToolOnCodeWithArgs( - new SkipBodyAction, "struct skipMe { skipMe(); };" + std::make_unique<SkipBodyAction>(), "struct skipMe { skipMe(); };" "skipMe::skipMe() : an_error{[](){;}} { more error }", Args)); EXPECT_TRUE(runToolOnCodeWithArgs( - new SkipBodyAction, + std::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 } };", + std::make_unique<SkipBodyAction>(), "struct skipMe { skipMe() : bases()... { error } };", Args)); EXPECT_FALSE(runToolOnCodeWithArgs( - new SkipBodyAction, "struct skipMeNot { skipMeNot() : an_error() { } };", + std::make_unique<SkipBodyAction>(), "struct skipMeNot { skipMeNot() : an_error() { } };", Args)); - EXPECT_FALSE(runToolOnCodeWithArgs(new SkipBodyAction, + EXPECT_FALSE(runToolOnCodeWithArgs(std::make_unique<SkipBodyAction>(), "struct skipMeNot { skipMeNot(); };" "skipMeNot::skipMeNot() : an_error() { }", Args)); // Try/catch EXPECT_TRUE(runToolOnCode( - new SkipBodyAction, + std::make_unique<SkipBodyAction>(), "void skipMe() try { an_error() } catch(error) { error };")); EXPECT_TRUE(runToolOnCode( - new SkipBodyAction, + std::make_unique<SkipBodyAction>(), "struct S { void skipMe() try { an_error() } catch(error) { error } };")); EXPECT_TRUE( - runToolOnCode(new SkipBodyAction, + runToolOnCode(std::make_unique<SkipBodyAction>(), "void skipMe() try { an_error() } catch(error) { error; }" "catch(error) { error } catch (error) { }")); EXPECT_FALSE(runToolOnCode( - new SkipBodyAction, + std::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 }" + std::make_unique<SkipBodyAction>(), "template<typename T> int skipMe() { an_error_here }" "int x = skipMe<int>();")); EXPECT_FALSE(runToolOnCodeWithArgs( - new SkipBodyAction, + std::make_unique<SkipBodyAction>(), "template<typename T> int skipMeNot() { an_error_here }", Args2)); } @@ -325,7 +325,7 @@ 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(std::make_unique<SkipBodyAction>(), "", Args)); EXPECT_FALSE(llvm::sys::fs::exists(DepFilePath.str())); EXPECT_FALSE(llvm::sys::fs::remove(DepFilePath.str())); } @@ -348,24 +348,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), "", + std::make_unique<CheckColoredDiagnosticsAction>(true), "", + {"-fcolor-diagnostics"})); + EXPECT_TRUE(runToolOnCodeWithArgs( + std::make_unique<CheckColoredDiagnosticsAction>(false), "", + {"-fno-color-diagnostics"})); + EXPECT_TRUE(runToolOnCodeWithArgs( + std::make_unique<CheckColoredDiagnosticsAction>(true), "", + {"-fno-color-diagnostics", "-fcolor-diagnostics"})); + EXPECT_TRUE(runToolOnCodeWithArgs( + std::make_unique<CheckColoredDiagnosticsAction>(false), "", + {"-fcolor-diagnostics", "-fno-color-diagnostics"})); + EXPECT_TRUE(runToolOnCodeWithArgs( + std::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( + std::make_unique<CheckColoredDiagnosticsAction>(false), "", + {"-fcolor-diagnostics"})); } TEST(ClangToolTest, ArgumentAdjusters) { @@ -657,7 +659,7 @@ TEST(runToolOnCode, TestResetDiagnostics) { // Should not crash EXPECT_FALSE( - runToolOnCode(new ResetDiagnosticAction, + runToolOnCode(std::make_unique<ResetDiagnosticAction>(), "struct Foo { Foo(int); ~Foo(); struct Fwd _fwd; };" "void func() { long x; Foo f(x); }")); } |