vladimir.plyashkun created this revision.
vladimir.plyashkun added a project: clang-tools-extra.
Herald added subscribers: xazax.hun, JDevlieghere, mgorny.
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
Repository:
rL LLVM
https://reviews.llvm.org/D35349
Files:
test/clang-apply-replacements/Inputs/basic/file1.yaml
test/clang-apply-replacements/Inputs/basic/file2.yaml
test/clang-apply-replacements/Inputs/conflict/file1.yaml
test/clang-apply-replacements/Inputs/conflict/file2.yaml
test/clang-apply-replacements/Inputs/conflict/file3.yaml
test/clang-apply-replacements/Inputs/crlf/file1.yaml
test/clang-apply-replacements/Inputs/format/no.yaml
test/clang-apply-replacements/Inputs/format/yes.yaml
unittests/clang-apply-replacements/ApplyReplacementsTest.cpp
unittests/clang-apply-replacements/CMakeLists.txt
Index: unittests/clang-apply-replacements/CMakeLists.txt
===================================================================
--- unittests/clang-apply-replacements/CMakeLists.txt
+++ unittests/clang-apply-replacements/CMakeLists.txt
@@ -8,6 +8,7 @@
)
add_extra_unittest(ClangApplyReplacementsTests
+ ApplyReplacementsTest.cpp
ReformattingTest.cpp
)
Index: unittests/clang-apply-replacements/ApplyReplacementsTest.cpp
===================================================================
--- /dev/null
+++ unittests/clang-apply-replacements/ApplyReplacementsTest.cpp
@@ -0,0 +1,49 @@
+//===- 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
Index: test/clang-apply-replacements/Inputs/format/yes.yaml
===================================================================
--- test/clang-apply-replacements/Inputs/format/yes.yaml
+++ test/clang-apply-replacements/Inputs/format/yes.yaml
@@ -4,6 +4,9 @@
MainSourceFile: yes.cpp
Diagnostics:
- DiagnosticName: test-yes
+ Message: Fix
+ FilePath: $(path)/yes.cpp
+ FileOffset: 494
Replacements:
- FilePath: $(path)/yes.cpp
Offset: 494
Index: test/clang-apply-replacements/Inputs/format/no.yaml
===================================================================
--- test/clang-apply-replacements/Inputs/format/no.yaml
+++ test/clang-apply-replacements/Inputs/format/no.yaml
@@ -2,6 +2,9 @@
MainSourceFile: no.cpp
Diagnostics:
- DiagnosticName: test-no
+ Message: Fix
+ FilePath: $(path)/no.cpp
+ FileOffset: 94
Replacements:
- FilePath: $(path)/no.cpp
Offset: 94
Index: test/clang-apply-replacements/Inputs/crlf/file1.yaml
===================================================================
--- test/clang-apply-replacements/Inputs/crlf/file1.yaml
+++ test/clang-apply-replacements/Inputs/crlf/file1.yaml
@@ -2,6 +2,9 @@
MainSourceFile: source1.cpp
Diagnostics:
- DiagnosticName: test-crlf
+ Message: Fix
+ FilePath: $(path)/crlf.cpp
+ FileOffset: 79
Replacements:
- FilePath: $(path)/crlf.cpp
Offset: 79
Index: test/clang-apply-replacements/Inputs/conflict/file3.yaml
===================================================================
--- test/clang-apply-replacements/Inputs/conflict/file3.yaml
+++ test/clang-apply-replacements/Inputs/conflict/file3.yaml
@@ -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
Index: test/clang-apply-replacements/Inputs/conflict/file2.yaml
===================================================================
--- test/clang-apply-replacements/Inputs/conflict/file2.yaml
+++ test/clang-apply-replacements/Inputs/conflict/file2.yaml
@@ -2,6 +2,9 @@
MainSourceFile: source2.cpp
Diagnostics:
- DiagnosticName: test-conflict
+ Message: Fix
+ FilePath: $(path)/common.h
+ FileOffset: 106
Replacements:
- FilePath: $(path)/common.h
Offset: 106
Index: test/clang-apply-replacements/Inputs/conflict/file1.yaml
===================================================================
--- test/clang-apply-replacements/Inputs/conflict/file1.yaml
+++ test/clang-apply-replacements/Inputs/conflict/file1.yaml
@@ -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
Index: test/clang-apply-replacements/Inputs/basic/file2.yaml
===================================================================
--- test/clang-apply-replacements/Inputs/basic/file2.yaml
+++ test/clang-apply-replacements/Inputs/basic/file2.yaml
@@ -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
Index: test/clang-apply-replacements/Inputs/basic/file1.yaml
===================================================================
--- test/clang-apply-replacements/Inputs/basic/file1.yaml
+++ test/clang-apply-replacements/Inputs/basic/file1.yaml
@@ -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
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits