Skip to content

Commit

Permalink
[Clang-Tidy] Preserve Message, FileOffset, FilePath in Clang-Tidy YAM…
Browse files Browse the repository at this point in the history
…L output

Summary:
To get properly integration Clang-Tidy with CLion IDE, next things were implemented:
* Preserve `Message`, `FileOffset`, `FilePath` in the clang-tidy output.
* Export all diagnostics, not just the ones with fixes
* Test-cases

Reviewers: alexfh, ilya-biryukov

Subscribers: mgorny, JDevlieghere, xazax.hun, cfe-commits

Tags: #clang-tools-extra

Patch by Vladimir Plyashkun!

Differential Revision: https://reviews.llvm.org/D35349

llvm-svn: 308015
alexfh committed Jul 14, 2017
1 parent 2745e17 commit 8b4fcb7
Showing 10 changed files with 84 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -2,6 +2,9 @@
MainSourceFile: source1.cpp
Diagnostics:
- DiagnosticName: test-basic
Message: Fix
FilePath: $(path)/basic.h
FileOffset: 242
Replacements:
- FilePath: $(path)/basic.h
Offset: 242
Original file line number Diff line number Diff line change
@@ -2,6 +2,9 @@
MainSourceFile: source2.cpp
Diagnostics:
- DiagnosticName: test-basic
Message: Fix
FilePath: $(path)/basic.h
FileOffset: 148
Replacements:
- FilePath: $(path)/basic.h
Offset: 148
Original file line number Diff line number Diff line change
@@ -2,6 +2,9 @@
MainSourceFile: source1.cpp
Diagnostics:
- DiagnosticName: test-conflict
Message: Fix
FilePath: $(path)/common.h
FileOffset: 106
Replacements:
- FilePath: $(path)/common.h
Offset: 106
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
---
MainSourceFile: source2.cpp
Diagnostics:
Diagnostics:
- DiagnosticName: test-conflict
Message: Fix
FilePath: $(path)/common.h
FileOffset: 106
Replacements:
- FilePath: $(path)/common.h
Offset: 106
Original file line number Diff line number Diff line change
@@ -2,6 +2,9 @@
MainSourceFile: source1.cpp
Diagnostics:
- DiagnosticName: test-conflict
Message: Fix
FilePath: $(path)/common.h
FileOffset: 169
Replacements:
- FilePath: $(path)/common.h
Offset: 169
Original file line number Diff line number Diff line change
@@ -2,7 +2,10 @@
MainSourceFile: source1.cpp
Diagnostics:
- DiagnosticName: test-crlf
Replacements:
Message: Fix
FilePath: $(path)/crlf.cpp
FileOffset: 79
Replacements:
- FilePath: $(path)/crlf.cpp
Offset: 79
Length: 1
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
---
MainSourceFile: no.cpp
Diagnostics:
Diagnostics:
- DiagnosticName: test-no
Replacements:
Message: Fix
FilePath: $(path)/no.cpp
FileOffset: 94
Replacements:
- FilePath: $(path)/no.cpp
Offset: 94
Length: 3
Original file line number Diff line number Diff line change
@@ -2,9 +2,12 @@
# so that formatting happens correctly.
---
MainSourceFile: yes.cpp
Diagnostics:
Diagnostics:
- DiagnosticName: test-yes
Replacements:
Message: Fix
FilePath: $(path)/yes.cpp
FileOffset: 494
Replacements:
- FilePath: $(path)/yes.cpp
Offset: 494
Length: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//===- clang-apply-replacements/ApplyReplacementsTest.cpp
//----------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "clang-apply-replacements/Tooling/ApplyReplacements.h"
#include "gtest/gtest.h"

using namespace clang::replace;
using namespace llvm;

namespace clang {
namespace tooling {

static TUDiagnostics
makeTUDiagnostics(const std::string &MainSourceFile, StringRef DiagnosticName,
const DiagnosticMessage &Message,
const StringMap<Replacements> &Replacements,
StringRef BuildDirectory) {
TUDiagnostics TUs;
TUs.push_back({MainSourceFile,
{{DiagnosticName,
Message,
Replacements,
{},
Diagnostic::Warning,
BuildDirectory}}});
return TUs;
}

// Test to ensure diagnostics with no fixes, will be merged correctly
// before applying.
TEST(ApplyReplacementsTest, mergeDiagnosticsWithNoFixes) {
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts(new DiagnosticOptions());
DiagnosticsEngine Diagnostics(
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()), DiagOpts.get());
FileManager Files((FileSystemOptions()));
SourceManager SM(Diagnostics, Files);
TUDiagnostics TUs =
makeTUDiagnostics("path/to/source.cpp", "diagnostic", {}, {}, "path/to");
FileToReplacementsMap ReplacementsMap;

EXPECT_TRUE(mergeAndDeduplicate(TUs, ReplacementsMap, SM));
EXPECT_TRUE(ReplacementsMap.empty());
}

} // end namespace tooling
} // end namespace clang
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ include_directories(
)

add_extra_unittest(ClangApplyReplacementsTests
ApplyReplacementsTest.cpp
ReformattingTest.cpp
)

0 comments on commit 8b4fcb7

Please sign in to comment.