diff options
author | Manuel Klimek <klimek@google.com> | 2012-10-25 08:49:11 +0000 |
---|---|---|
committer | Manuel Klimek <klimek@google.com> | 2012-10-25 08:49:11 +0000 |
commit | 9fb6b27e6d584ac339363357335f8d6de3a652ac (patch) | |
tree | ea767b2da148157ac1ab183dbbd8c60a72c0ab2e /unittests | |
parent | 8e1cee6f23e2552b96b81e5ef419ab3f69c5b5c2 (diff) | |
download | clang-9fb6b27e6d584ac339363357335f8d6de3a652ac.tar.gz |
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
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/Tooling/ToolingTest.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/unittests/Tooling/ToolingTest.cpp b/unittests/Tooling/ToolingTest.cpp index fb3af2678c..7846df3b93 100644 --- a/unittests/Tooling/ToolingTest.cpp +++ b/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::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 |