summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format/SortIncludesTest.cpp
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2017-06-29 23:20:54 +0000
committerChandler Carruth <chandlerc@gmail.com>2017-06-29 23:20:54 +0000
commitd676ab13540473bdb15c2d204e4cd84bf1fcea93 (patch)
tree179cb4ff6441ccddac878e66ba48c7b3d24ee46b /clang/unittests/Format/SortIncludesTest.cpp
parent0e35ea3b7c63f43d27f505fac23bfa9b0c706c4b (diff)
downloadbcm5719-llvm-d676ab13540473bdb15c2d204e4cd84bf1fcea93.tar.gz
bcm5719-llvm-d676ab13540473bdb15c2d204e4cd84bf1fcea93.zip
[clang-format] Switch to case-insensitive header matching and use it to
improve support for LLVM-style include sorting. This really is a collection of improvements to the rules for LLVM include sorting: - We have gmock headers now, so it adds support for those to one of the categories. - LLVM does use 'FooTest.cpp' files to test 'Foo.h' so it adds that suffix for finding a main header. - At times the test file's case may not match the header file's case, so switch to case-insensitive regex matching of header names. With this set of changes, I can't spot any misbehaviors when re-sorting all of LLVM's unittest '#include' lines. Thanks to Eric and Daniel for help testing and refining the patch during review! Differential Revision: https://reviews.llvm.org/D33932 llvm-svn: 306759
Diffstat (limited to 'clang/unittests/Format/SortIncludesTest.cpp')
-rw-r--r--clang/unittests/Format/SortIncludesTest.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/clang/unittests/Format/SortIncludesTest.cpp b/clang/unittests/Format/SortIncludesTest.cpp
index c3c56a81304..1128ed829ff 100644
--- a/clang/unittests/Format/SortIncludesTest.cpp
+++ b/clang/unittests/Format/SortIncludesTest.cpp
@@ -266,6 +266,29 @@ TEST_F(SortIncludesTest, LeavesMainHeaderFirst) {
"a.cc"));
}
+TEST_F(SortIncludesTest, SupportCaseInsensitiveMatching) {
+ // Setup an regex for main includes so we can cover those as well.
+ Style.IncludeIsMainRegex = "([-_](test|unittest))?$";
+
+ // Ensure both main header detection and grouping work in a case insensitive
+ // manner.
+ EXPECT_EQ("#include \"llvm/A.h\"\n"
+ "#include \"b.h\"\n"
+ "#include \"c.h\"\n"
+ "#include \"LLVM/z.h\"\n"
+ "#include \"llvm/X.h\"\n"
+ "#include \"GTest/GTest.h\"\n"
+ "#include \"gmock/gmock.h\"\n",
+ sort("#include \"c.h\"\n"
+ "#include \"b.h\"\n"
+ "#include \"GTest/GTest.h\"\n"
+ "#include \"llvm/A.h\"\n"
+ "#include \"gmock/gmock.h\"\n"
+ "#include \"llvm/X.h\"\n"
+ "#include \"LLVM/z.h\"\n",
+ "a_TEST.cc"));
+}
+
TEST_F(SortIncludesTest, NegativePriorities) {
Style.IncludeCategories = {{".*important_os_header.*", -1}, {".*", 1}};
EXPECT_EQ("#include \"important_os_header.h\"\n"
OpenPOWER on IntegriCloud