|
@@ -62,10 +62,10 @@ class FindTopLevelDeclConsumer : public clang::ASTConsumer {
|
|
|
|
|
|
TEST(runToolOnCode, FindsNoTopLevelDeclOnEmptyCode) {
|
|
TEST(runToolOnCode, FindsNoTopLevelDeclOnEmptyCode) {
|
|
bool FoundTopLevelDecl = false;
|
|
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);
|
|
EXPECT_FALSE(FoundTopLevelDecl);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -102,17 +102,17 @@ bool FindClassDeclX(ASTUnit *AST) {
|
|
|
|
|
|
TEST(runToolOnCode, FindsClassDecl) {
|
|
TEST(runToolOnCode, FindsClassDecl) {
|
|
bool FoundClassDeclX = false;
|
|
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);
|
|
EXPECT_TRUE(FoundClassDeclX);
|
|
|
|
|
|
FoundClassDeclX = false;
|
|
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);
|
|
EXPECT_FALSE(FoundClassDeclX);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -160,8 +160,8 @@ TEST(ToolInvocation, TestMapVirtualFile) {
|
|
Args.push_back("-Idef");
|
|
Args.push_back("-Idef");
|
|
Args.push_back("-fsyntax-only");
|
|
Args.push_back("-fsyntax-only");
|
|
Args.push_back("test.cpp");
|
|
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(
|
|
InMemoryFileSystem->addFile(
|
|
"test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("#include <abc>\n"));
|
|
"test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("#include <abc>\n"));
|
|
InMemoryFileSystem->addFile("def/abc", 0,
|
|
InMemoryFileSystem->addFile("def/abc", 0,
|
|
@@ -186,8 +186,8 @@ TEST(ToolInvocation, TestVirtualModulesCompilation) {
|
|
Args.push_back("-Idef");
|
|
Args.push_back("-Idef");
|
|
Args.push_back("-fsyntax-only");
|
|
Args.push_back("-fsyntax-only");
|
|
Args.push_back("test.cpp");
|
|
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(
|
|
InMemoryFileSystem->addFile(
|
|
"test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("#include <abc>\n"));
|
|
"test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("#include <abc>\n"));
|
|
InMemoryFileSystem->addFile("def/abc", 0,
|
|
InMemoryFileSystem->addFile("def/abc", 0,
|
|
@@ -257,61 +257,61 @@ TEST(runToolOnCode, TestSkipFunctionBody) {
|
|
std::vector<std::string> Args = {"-std=c++11"};
|
|
std::vector<std::string> Args = {"-std=c++11"};
|
|
std::vector<std::string> Args2 = {"-fno-delayed-template-parsing"};
|
|
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 }"));
|
|
"int skipMe() { an_error_here }"));
|
|
- EXPECT_FALSE(runToolOnCode(new SkipBodyAction,
|
|
|
|
|
|
+ EXPECT_FALSE(runToolOnCode(std::make_unique<SkipBodyAction>(),
|
|
"int skipMeNot() { an_error_here }"));
|
|
"int skipMeNot() { an_error_here }"));
|
|
|
|
|
|
// Test constructors with initializers
|
|
// Test constructors with initializers
|
|
EXPECT_TRUE(runToolOnCodeWithArgs(
|
|
EXPECT_TRUE(runToolOnCodeWithArgs(
|
|
- new SkipBodyAction,
|
|
|
|
|
|
+ std::make_unique<SkipBodyAction>(),
|
|
"struct skipMe { skipMe() : an_error() { more error } };", Args));
|
|
"struct skipMe { skipMe() : an_error() { more error } };", Args));
|
|
EXPECT_TRUE(runToolOnCodeWithArgs(
|
|
EXPECT_TRUE(runToolOnCodeWithArgs(
|
|
- new SkipBodyAction, "struct skipMe { skipMe(); };"
|
|
|
|
|
|
+ std::make_unique<SkipBodyAction>(), "struct skipMe { skipMe(); };"
|
|
"skipMe::skipMe() : an_error([](){;}) { more error }",
|
|
"skipMe::skipMe() : an_error([](){;}) { more error }",
|
|
Args));
|
|
Args));
|
|
EXPECT_TRUE(runToolOnCodeWithArgs(
|
|
EXPECT_TRUE(runToolOnCodeWithArgs(
|
|
- new SkipBodyAction, "struct skipMe { skipMe(); };"
|
|
|
|
|
|
+ std::make_unique<SkipBodyAction>(), "struct skipMe { skipMe(); };"
|
|
"skipMe::skipMe() : an_error{[](){;}} { more error }",
|
|
"skipMe::skipMe() : an_error{[](){;}} { more error }",
|
|
Args));
|
|
Args));
|
|
EXPECT_TRUE(runToolOnCodeWithArgs(
|
|
EXPECT_TRUE(runToolOnCodeWithArgs(
|
|
- new SkipBodyAction,
|
|
|
|
|
|
+ std::make_unique<SkipBodyAction>(),
|
|
"struct skipMe { skipMe(); };"
|
|
"struct skipMe { skipMe(); };"
|
|
"skipMe::skipMe() : a<b<c>(e)>>(), f{}, g() { error }",
|
|
"skipMe::skipMe() : a<b<c>(e)>>(), f{}, g() { error }",
|
|
Args));
|
|
Args));
|
|
EXPECT_TRUE(runToolOnCodeWithArgs(
|
|
EXPECT_TRUE(runToolOnCodeWithArgs(
|
|
- new SkipBodyAction, "struct skipMe { skipMe() : bases()... { error } };",
|
|
|
|
|
|
+ std::make_unique<SkipBodyAction>(), "struct skipMe { skipMe() : bases()... { error } };",
|
|
Args));
|
|
Args));
|
|
|
|
|
|
EXPECT_FALSE(runToolOnCodeWithArgs(
|
|
EXPECT_FALSE(runToolOnCodeWithArgs(
|
|
- new SkipBodyAction, "struct skipMeNot { skipMeNot() : an_error() { } };",
|
|
|
|
|
|
+ std::make_unique<SkipBodyAction>(), "struct skipMeNot { skipMeNot() : an_error() { } };",
|
|
Args));
|
|
Args));
|
|
- EXPECT_FALSE(runToolOnCodeWithArgs(new SkipBodyAction,
|
|
|
|
|
|
+ EXPECT_FALSE(runToolOnCodeWithArgs(std::make_unique<SkipBodyAction>(),
|
|
"struct skipMeNot { skipMeNot(); };"
|
|
"struct skipMeNot { skipMeNot(); };"
|
|
"skipMeNot::skipMeNot() : an_error() { }",
|
|
"skipMeNot::skipMeNot() : an_error() { }",
|
|
Args));
|
|
Args));
|
|
|
|
|
|
// Try/catch
|
|
// Try/catch
|
|
EXPECT_TRUE(runToolOnCode(
|
|
EXPECT_TRUE(runToolOnCode(
|
|
- new SkipBodyAction,
|
|
|
|
|
|
+ std::make_unique<SkipBodyAction>(),
|
|
"void skipMe() try { an_error() } catch(error) { error };"));
|
|
"void skipMe() try { an_error() } catch(error) { error };"));
|
|
EXPECT_TRUE(runToolOnCode(
|
|
EXPECT_TRUE(runToolOnCode(
|
|
- new SkipBodyAction,
|
|
|
|
|
|
+ std::make_unique<SkipBodyAction>(),
|
|
"struct S { void skipMe() try { an_error() } catch(error) { error } };"));
|
|
"struct S { void skipMe() try { an_error() } catch(error) { error } };"));
|
|
EXPECT_TRUE(
|
|
EXPECT_TRUE(
|
|
- runToolOnCode(new SkipBodyAction,
|
|
|
|
|
|
+ runToolOnCode(std::make_unique<SkipBodyAction>(),
|
|
"void skipMe() try { an_error() } catch(error) { error; }"
|
|
"void skipMe() try { an_error() } catch(error) { error; }"
|
|
"catch(error) { error } catch (error) { }"));
|
|
"catch(error) { error } catch (error) { }"));
|
|
EXPECT_FALSE(runToolOnCode(
|
|
EXPECT_FALSE(runToolOnCode(
|
|
- new SkipBodyAction,
|
|
|
|
|
|
+ std::make_unique<SkipBodyAction>(),
|
|
"void skipMe() try something;")); // don't crash while parsing
|
|
"void skipMe() try something;")); // don't crash while parsing
|
|
|
|
|
|
// Template
|
|
// Template
|
|
EXPECT_TRUE(runToolOnCode(
|
|
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>();"));
|
|
"int x = skipMe<int>();"));
|
|
EXPECT_FALSE(runToolOnCodeWithArgs(
|
|
EXPECT_FALSE(runToolOnCodeWithArgs(
|
|
- new SkipBodyAction,
|
|
|
|
|
|
+ std::make_unique<SkipBodyAction>(),
|
|
"template<typename T> int skipMeNot() { an_error_here }", Args2));
|
|
"template<typename T> int skipMeNot() { an_error_here }", Args2));
|
|
}
|
|
}
|
|
|
|
|
|
@@ -325,7 +325,7 @@ TEST(runToolOnCodeWithArgs, TestNoDepFile) {
|
|
Args.push_back(DepFilePath.str());
|
|
Args.push_back(DepFilePath.str());
|
|
Args.push_back("-MF");
|
|
Args.push_back("-MF");
|
|
Args.push_back(DepFilePath.str());
|
|
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::exists(DepFilePath.str()));
|
|
EXPECT_FALSE(llvm::sys::fs::remove(DepFilePath.str()));
|
|
EXPECT_FALSE(llvm::sys::fs::remove(DepFilePath.str()));
|
|
}
|
|
}
|
|
@@ -348,24 +348,26 @@ private:
|
|
};
|
|
};
|
|
|
|
|
|
TEST(runToolOnCodeWithArgs, DiagnosticsColor) {
|
|
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(
|
|
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"}));
|
|
{"-fno-color-diagnostics", "-fdiagnostics-color=always"}));
|
|
|
|
|
|
// Check that this test would fail if ShowColors is not what it should.
|
|
// 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) {
|
|
TEST(ClangToolTest, ArgumentAdjusters) {
|
|
@@ -657,7 +659,7 @@ TEST(runToolOnCode, TestResetDiagnostics) {
|
|
|
|
|
|
// Should not crash
|
|
// Should not crash
|
|
EXPECT_FALSE(
|
|
EXPECT_FALSE(
|
|
- runToolOnCode(new ResetDiagnosticAction,
|
|
|
|
|
|
+ runToolOnCode(std::make_unique<ResetDiagnosticAction>(),
|
|
"struct Foo { Foo(int); ~Foo(); struct Fwd _fwd; };"
|
|
"struct Foo { Foo(int); ~Foo(); struct Fwd _fwd; };"
|
|
"void func() { long x; Foo f(x); }"));
|
|
"void func() { long x; Foo f(x); }"));
|
|
}
|
|
}
|