Adds the possibility to inject a callback that's called after each translation unit is processed.

This is important when one wants to deduplicate results during one run over a translation unit by pointer identity of AST nodes.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166671 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/unittests/Tooling/ToolingTest.cpp b/unittests/Tooling/ToolingTest.cpp
index fb3af26..7846df3 100644
--- a/unittests/Tooling/ToolingTest.cpp
+++ b/unittests/Tooling/ToolingTest.cpp
@@ -130,5 +130,35 @@
   EXPECT_TRUE(Invocation.run());
 }
 
+struct VerifyEndCallback : public EndOfSourceFileCallback {
+  VerifyEndCallback() : Called(0), Matched(false) {}
+  virtual void run() {
+    ++Called;
+  }
+  ASTConsumer *newASTConsumer() {
+    return new FindTopLevelDeclConsumer(&Matched);
+  }
+  unsigned Called;
+  bool Matched;
+};
+
+TEST(newFrontendActionFactory, InjectsEndOfSourceFileCallback) {
+  VerifyEndCallback EndCallback;
+
+  FixedCompilationDatabase Compilations("/", std::vector<std::string>());
+  std::vector<std::string> Sources;
+  Sources.push_back("/a.cc");
+  Sources.push_back("/b.cc");
+  ClangTool Tool(Compilations, Sources);
+
+  Tool.mapVirtualFile("/a.cc", "void a() {}");
+  Tool.mapVirtualFile("/b.cc", "void b() {}");
+
+  Tool.run(newFrontendActionFactory(&EndCallback, &EndCallback));
+
+  EXPECT_TRUE(EndCallback.Matched);
+  EXPECT_EQ(2u, EndCallback.Called);
+}
+
 } // end namespace tooling
 } // end namespace clang