summaryrefslogtreecommitdiff
path: root/unittests/Tooling
diff options
context:
space:
mode:
authorDmitri Gribenko <gribozavr@gmail.com>2019-08-30 09:29:34 +0000
committerDmitri Gribenko <gribozavr@gmail.com>2019-08-30 09:29:34 +0000
commitb6cbdf1b70fcaf54b91086c1fb922a2f99282172 (patch)
tree13b037130c4490fefcc458ef93f5c92034487783 /unittests/Tooling
parent99b2bc4f952874990519d75bb61631959f8fd6c1 (diff)
downloadclang-b6cbdf1b70fcaf54b91086c1fb922a2f99282172.tar.gz
[Tooling] Migrated APIs that take ownership of objects to unique_ptr
Subscribers: jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66960 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@370451 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Tooling')
-rw-r--r--unittests/Tooling/CommentHandlerTest.cpp4
-rw-r--r--unittests/Tooling/RefactoringTest.cpp2
-rw-r--r--unittests/Tooling/TestVisitor.h4
-rw-r--r--unittests/Tooling/ToolingTest.cpp96
4 files changed, 54 insertions, 52 deletions
diff --git a/unittests/Tooling/CommentHandlerTest.cpp b/unittests/Tooling/CommentHandlerTest.cpp
index 5ceed95b98..7eb11ccd6e 100644
--- a/unittests/Tooling/CommentHandlerTest.cpp
+++ b/unittests/Tooling/CommentHandlerTest.cpp
@@ -55,8 +55,8 @@ public:
CommentVerifier GetVerifier();
protected:
- ASTFrontendAction *CreateTestAction() override {
- return new CommentHandlerAction(this);
+ std::unique_ptr<ASTFrontendAction> CreateTestAction() override {
+ return std::make_unique<CommentHandlerAction>(this);
}
private:
diff --git a/unittests/Tooling/RefactoringTest.cpp b/unittests/Tooling/RefactoringTest.cpp
index b5c56e907a..5949c53d8e 100644
--- a/unittests/Tooling/RefactoringTest.cpp
+++ b/unittests/Tooling/RefactoringTest.cpp
@@ -650,7 +650,7 @@ template <typename T>
class TestVisitor : public clang::RecursiveASTVisitor<T> {
public:
bool runOver(StringRef Code) {
- return runToolOnCode(new TestAction(this), Code);
+ return runToolOnCode(std::make_unique<TestAction>(this), Code);
}
protected:
diff --git a/unittests/Tooling/TestVisitor.h b/unittests/Tooling/TestVisitor.h
index 95252b82c6..751ca74d1a 100644
--- a/unittests/Tooling/TestVisitor.h
+++ b/unittests/Tooling/TestVisitor.h
@@ -85,8 +85,8 @@ public:
}
protected:
- virtual ASTFrontendAction* CreateTestAction() {
- return new TestAction(this);
+ virtual std::unique_ptr<ASTFrontendAction> CreateTestAction() {
+ return std::make_unique<TestAction>(this);
}
class FindConsumer : public ASTConsumer {
diff --git a/unittests/Tooling/ToolingTest.cpp b/unittests/Tooling/ToolingTest.cpp
index 447b9973e4..c22d0bdca4 100644
--- a/unittests/Tooling/ToolingTest.cpp
+++ b/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); }"));
}