Add test for injecting diagnostic consumers into a ClangTool.

As suggested by pcc on 194226.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194494 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/unittests/Tooling/ToolingTest.cpp b/unittests/Tooling/ToolingTest.cpp
index 40360fb..2afe929 100644
--- a/unittests/Tooling/ToolingTest.cpp
+++ b/unittests/Tooling/ToolingTest.cpp
@@ -321,5 +321,17 @@
   EXPECT_EQ(1u, Consumer.NumDiagnosticsSeen);
 }
 
+TEST(ClangToolTest, InjectDiagnosticConsumerInBuildASTs) {
+  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);
+  std::vector<ASTUnit*> ASTs;
+  Tool.buildASTs(ASTs);
+  EXPECT_EQ(1u, ASTs.size());
+  EXPECT_EQ(1u, Consumer.NumDiagnosticsSeen);
+}
+
 } // end namespace tooling
 } // end namespace clang