From 8246d87db09f1cfbe13a76379bd550189496a925 Mon Sep 17 00:00:00 2001 From: Manuel Klimek Date: Thu, 25 Oct 2012 08:49:11 +0000 Subject: 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. llvm-svn: 166671 --- clang/unittests/Tooling/ToolingTest.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'clang/unittests/Tooling/ToolingTest.cpp') diff --git a/clang/unittests/Tooling/ToolingTest.cpp b/clang/unittests/Tooling/ToolingTest.cpp index fb3af2678c5..7846df3b934 100644 --- a/clang/unittests/Tooling/ToolingTest.cpp +++ b/clang/unittests/Tooling/ToolingTest.cpp @@ -130,5 +130,35 @@ TEST(ToolInvocation, TestMapVirtualFile) { 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::vector 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 -- cgit v1.2.3