[clang-tidy] Make clang-format and include-order-check coherent
authorKadir Cetinkaya <kadircet@google.com>
Tue, 17 Nov 2020 09:28:52 +0000 (10:28 +0100)
committerKadir Cetinkaya <kadircet@google.com>
Tue, 17 Nov 2020 13:54:10 +0000 (14:54 +0100)
LLVM style puts both gtest and gmock to the end of the include list.
But llvm-include-order-check was only moving gtest headers to the end, resulting
in a false tidy-warning.

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

clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/gmock/foo.h [new file with mode: 0644]
clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp

index 834a49a..c962fb3 100644 (file)
@@ -67,7 +67,8 @@ static int getPriority(StringRef Filename, bool IsAngled, bool IsMainModule) {
     return 2;
 
   // System headers are sorted to the end.
-  if (IsAngled || Filename.startswith("gtest/"))
+  if (IsAngled || Filename.startswith("gtest/") ||
+      Filename.startswith("gmock/"))
     return 3;
 
   // Other headers are inserted between the main module header and LLVM headers.
diff --git a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/gmock/foo.h b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/gmock/foo.h
new file mode 100644 (file)
index 0000000..e69de29
index 7272353..6dd3d6a 100644 (file)
@@ -3,6 +3,7 @@
 // CHECK-MESSAGES: [[@LINE+2]]:1: warning: #includes are not sorted properly
 #include "j.h"
 #include "gtest/foo.h"
+#include "gmock/foo.h"
 #include "i.h"
 #include <s.h>
 #include "llvm/a.h"
@@ -16,6 +17,7 @@
 // CHECK-FIXES-NEXT: #include "clang/b.h"
 // CHECK-FIXES-NEXT: #include "llvm-c/d.h" // -c
 // CHECK-FIXES-NEXT: #include "llvm/a.h"
+// CHECK-FIXES-NEXT: #include "gmock/foo.h"
 // CHECK-FIXES-NEXT: #include "gtest/foo.h"
 // CHECK-FIXES-NEXT: #include <s.h>