[clang-tools-extra] r308015 - [Clang-Tidy] Preserve Message, FileOffset, FilePath in Clang-Tidy YAML output

Alexander Kornienko via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 14 03:37:46 PDT 2017


Author: alexfh
Date: Fri Jul 14 03:37:46 2017
New Revision: 308015

URL: http://llvm.org/viewvc/llvm-project?rev=308015&view=rev
Log:
[Clang-Tidy] Preserve Message, FileOffset, FilePath in Clang-Tidy YAML 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

Added:
    clang-tools-extra/trunk/unittests/clang-apply-replacements/ApplyReplacementsTest.cpp
Modified:
    clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/basic/file1.yaml
    clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/basic/file2.yaml
    clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file1.yaml
    clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file2.yaml
    clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file3.yaml
    clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/crlf/file1.yaml
    clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/format/no.yaml
    clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/format/yes.yaml
    clang-tools-extra/trunk/unittests/clang-apply-replacements/CMakeLists.txt

Modified: clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/basic/file1.yaml
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/basic/file1.yaml?rev=308015&r1=308014&r2=308015&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/basic/file1.yaml (original)
+++ clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/basic/file1.yaml Fri Jul 14 03:37:46 2017
@@ -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

Modified: clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/basic/file2.yaml
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/basic/file2.yaml?rev=308015&r1=308014&r2=308015&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/basic/file2.yaml (original)
+++ clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/basic/file2.yaml Fri Jul 14 03:37:46 2017
@@ -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

Modified: clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file1.yaml
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file1.yaml?rev=308015&r1=308014&r2=308015&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file1.yaml (original)
+++ clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file1.yaml Fri Jul 14 03:37:46 2017
@@ -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

Modified: clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file2.yaml
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file2.yaml?rev=308015&r1=308014&r2=308015&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file2.yaml (original)
+++ clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file2.yaml Fri Jul 14 03:37:46 2017
@@ -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

Modified: clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file3.yaml
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file3.yaml?rev=308015&r1=308014&r2=308015&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file3.yaml (original)
+++ clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file3.yaml Fri Jul 14 03:37:46 2017
@@ -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

Modified: clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/crlf/file1.yaml
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/crlf/file1.yaml?rev=308015&r1=308014&r2=308015&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/crlf/file1.yaml (original)
+++ clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/crlf/file1.yaml Fri Jul 14 03:37:46 2017
@@ -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

Modified: clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/format/no.yaml
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/format/no.yaml?rev=308015&r1=308014&r2=308015&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/format/no.yaml (original)
+++ clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/format/no.yaml Fri Jul 14 03:37:46 2017
@@ -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

Modified: clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/format/yes.yaml
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/format/yes.yaml?rev=308015&r1=308014&r2=308015&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/format/yes.yaml (original)
+++ clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/format/yes.yaml Fri Jul 14 03:37:46 2017
@@ -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

Added: clang-tools-extra/trunk/unittests/clang-apply-replacements/ApplyReplacementsTest.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-apply-replacements/ApplyReplacementsTest.cpp?rev=308015&view=auto
==============================================================================
--- clang-tools-extra/trunk/unittests/clang-apply-replacements/ApplyReplacementsTest.cpp (added)
+++ clang-tools-extra/trunk/unittests/clang-apply-replacements/ApplyReplacementsTest.cpp Fri Jul 14 03:37:46 2017
@@ -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

Modified: clang-tools-extra/trunk/unittests/clang-apply-replacements/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-apply-replacements/CMakeLists.txt?rev=308015&r1=308014&r2=308015&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clang-apply-replacements/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/unittests/clang-apply-replacements/CMakeLists.txt Fri Jul 14 03:37:46 2017
@@ -8,6 +8,7 @@ include_directories(
   )
 
 add_extra_unittest(ClangApplyReplacementsTests
+  ApplyReplacementsTest.cpp
   ReformattingTest.cpp
   )
 




More information about the cfe-commits mailing list