summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Tooling/ToolingTest.cpp
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2013-11-07 23:18:05 +0000
committerManuel Klimek <klimek@google.com>2013-11-07 23:18:05 +0000
commit640830142100ea828ba54b42c68ccc4b3dd1d8ea (patch)
treea032fbc9681efa2972275dac50d36a7cbd62cec3 /clang/unittests/Tooling/ToolingTest.cpp
parent594b8c934f79de7c2085a6ca7fb519648a7ff684 (diff)
downloadbcm5719-llvm-640830142100ea828ba54b42c68ccc4b3dd1d8ea.tar.gz
bcm5719-llvm-640830142100ea828ba54b42c68ccc4b3dd1d8ea.zip
Adds the ability to inject a DiagnosticConsumer into ClangTools.
llvm-svn: 194226
Diffstat (limited to 'clang/unittests/Tooling/ToolingTest.cpp')
-rw-r--r--clang/unittests/Tooling/ToolingTest.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/clang/unittests/Tooling/ToolingTest.cpp b/clang/unittests/Tooling/ToolingTest.cpp
index 25df601df82..40360fb45e1 100644
--- a/clang/unittests/Tooling/ToolingTest.cpp
+++ b/clang/unittests/Tooling/ToolingTest.cpp
@@ -302,5 +302,24 @@ TEST(ClangToolTest, BuildASTs) {
}
#endif
+struct TestDiagnosticConsumer : public DiagnosticConsumer {
+ TestDiagnosticConsumer() : NumDiagnosticsSeen(0) {}
+ virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
+ const Diagnostic &Info) {
+ ++NumDiagnosticsSeen;
+ }
+ unsigned NumDiagnosticsSeen;
+};
+
+TEST(ClangToolTest, InjectDiagnosticConsumer) {
+ FixedCompilationDatabase Compilations("/", std::vector<std::string>());
+ ClangTool Tool(Compilations, std::vector<std::string>(1, "/a.cc"));
+ Tool.mapVirtualFile("/a.cc", "int x = undeclared;");
+ TestDiagnosticConsumer Consumer;
+ Tool.setDiagnosticConsumer(&Consumer);
+ Tool.run(newFrontendActionFactory<SyntaxOnlyAction>());
+ EXPECT_EQ(1u, Consumer.NumDiagnosticsSeen);
+}
+
} // end namespace tooling
} // end namespace clang
OpenPOWER on IntegriCloud