summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/unittests/clang-tidy
diff options
context:
space:
mode:
authorSam McCall <sam.mccall@gmail.com>2018-11-02 10:01:59 +0000
committerSam McCall <sam.mccall@gmail.com>2018-11-02 10:01:59 +0000
commitcb50e23ba86ecfbb22f0eb1eec2fde9cc0c55569 (patch)
tree1b20436cdd349fdeebc06a52c670ee1d07b4ea09 /clang-tools-extra/unittests/clang-tidy
parent31d012eb2f2d839c0e37bf65bb868441b90b3e33 (diff)
downloadbcm5719-llvm-cb50e23ba86ecfbb22f0eb1eec2fde9cc0c55569.tar.gz
bcm5719-llvm-cb50e23ba86ecfbb22f0eb1eec2fde9cc0c55569.zip
[clang-tidy] Get ClangTidyContext out of the business of storing diagnostics. NFC
Summary: Currently ClangTidyContext::diag() sends the diagnostics to a DiagnosticsEngine, which probably delegates to a ClangTidyDiagnosticsConsumer, which is supposed to go back and populate ClangTidyContext::Errors. After this patch, the diagnostics are stored in the ClangTidyDiagnosticsConsumer itself and can be retrieved from there. Why? - the round-trip from context -> engine -> consumer -> context is confusing and makes it harder to establish layering between these things. - context does too many things, and makes it hard to use clang-tidy as a library - everyone who actually wants the diagnostics has access to the ClangTidyDiagnosticsConsumer The most natural implementation (ClangTidyDiagnosticsConsumer::take() finalizes diagnostics) causes a test failure: clang-tidy-run-with-database.cpp asserts that clang-tidy exits successfully when trying to process a file that doesn't exist. In clang-tidy today, this happens because finish() is never called, so the diagnostic is never flushed. This looks like a bug to me. For now, this patch carefully preserves that behavior, but I'll ping the authors to see whether it's deliberate and worth preserving. Reviewers: hokein Subscribers: xazax.hun, cfe-commits, alexfh Differential Revision: https://reviews.llvm.org/D53953 llvm-svn: 345961
Diffstat (limited to 'clang-tools-extra/unittests/clang-tidy')
-rw-r--r--clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h b/clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h
index 2d2675489aa..f6e8e8efdcf 100644
--- a/clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h
+++ b/clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h
@@ -118,15 +118,15 @@ runCheckOnCode(StringRef Code, std::vector<ClangTidyError> *Errors = nullptr,
Invocation.setDiagnosticConsumer(&DiagConsumer);
if (!Invocation.run()) {
std::string ErrorText;
- for (const auto &Error : Context.getErrors()) {
+ for (const auto &Error : DiagConsumer.take()) {
ErrorText += Error.Message.Message + "\n";
}
llvm::report_fatal_error(ErrorText);
}
- DiagConsumer.finish();
tooling::Replacements Fixes;
- for (const ClangTidyError &Error : Context.getErrors()) {
+ std::vector<ClangTidyError> Diags = DiagConsumer.take();
+ for (const ClangTidyError &Error : Diags) {
for (const auto &FileAndFixes : Error.Fix) {
for (const auto &Fix : FileAndFixes.second) {
auto Err = Fixes.add(Fix);
@@ -139,7 +139,7 @@ runCheckOnCode(StringRef Code, std::vector<ClangTidyError> *Errors = nullptr,
}
}
if (Errors)
- *Errors = Context.getErrors();
+ *Errors = std::move(Diags);
auto Result = tooling::applyAllReplacements(Code, Fixes);
if (!Result) {
// FIXME: propogate the error.
OpenPOWER on IntegriCloud