diff options
author | Daniel Jasper <djasper@google.com> | 2016-03-21 14:11:27 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2016-03-21 14:11:27 +0000 |
commit | 9c8ff3551ace965a3232fc4a1b53a75015a706cf (patch) | |
tree | b79665461141afc99d5bf130a71991d5ac645aaa /clang/unittests/Format/SortIncludesTest.cpp | |
parent | 4aeab5fbf241a06fbd8fef719b94466da7f2f6d4 (diff) | |
download | bcm5719-llvm-9c8ff3551ace965a3232fc4a1b53a75015a706cf.tar.gz bcm5719-llvm-9c8ff3551ace965a3232fc4a1b53a75015a706cf.zip |
clang-format: Make include sorting's main include detection configurable.
This patch adds a regular expression to configure suffixes of an
included file to check whether it is the "main" include of the current
file. Previously, clang-format has allowed arbitrary suffixes on the
formatted file, which is still the case when no IncludeMainRegex is
specified.
llvm-svn: 263943
Diffstat (limited to 'clang/unittests/Format/SortIncludesTest.cpp')
-rw-r--r-- | clang/unittests/Format/SortIncludesTest.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/clang/unittests/Format/SortIncludesTest.cpp b/clang/unittests/Format/SortIncludesTest.cpp index 9e5f2675f08..c8a43fc6240 100644 --- a/clang/unittests/Format/SortIncludesTest.cpp +++ b/clang/unittests/Format/SortIncludesTest.cpp @@ -175,6 +175,7 @@ TEST_F(SortIncludesTest, HandlesMultilineIncludes) { } TEST_F(SortIncludesTest, LeavesMainHeaderFirst) { + Style.IncludeIsMainRegex = "([-_](test|unittest))?$"; EXPECT_EQ("#include \"llvm/a.h\"\n" "#include \"b.h\"\n" "#include \"c.h\"\n", @@ -188,7 +189,7 @@ TEST_F(SortIncludesTest, LeavesMainHeaderFirst) { sort("#include \"llvm/a.h\"\n" "#include \"c.h\"\n" "#include \"b.h\"\n", - "a_main.cc")); + "a_test.cc")); EXPECT_EQ("#include \"llvm/input.h\"\n" "#include \"b.h\"\n" "#include \"c.h\"\n", @@ -197,6 +198,24 @@ TEST_F(SortIncludesTest, LeavesMainHeaderFirst) { "#include \"b.h\"\n", "input.mm")); + // Don't allow prefixes. + EXPECT_EQ("#include \"b.h\"\n" + "#include \"c.h\"\n" + "#include \"llvm/not_a.h\"\n", + sort("#include \"llvm/not_a.h\"\n" + "#include \"c.h\"\n" + "#include \"b.h\"\n", + "a.cc")); + + // Don't do this for _main and other suffixes. + EXPECT_EQ("#include \"b.h\"\n" + "#include \"c.h\"\n" + "#include \"llvm/a.h\"\n", + sort("#include \"llvm/a.h\"\n" + "#include \"c.h\"\n" + "#include \"b.h\"\n", + "a_main.cc")); + // Don't do this in headers. EXPECT_EQ("#include \"b.h\"\n" "#include \"c.h\"\n" |