summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format
diff options
context:
space:
mode:
authorAntonio Maiorano <amaiorano@gmail.com>2017-01-20 01:22:42 +0000
committerAntonio Maiorano <amaiorano@gmail.com>2017-01-20 01:22:42 +0000
commit7eb7507aeb3552400c8a1f4dc82bb2212260c0da (patch)
treec1ba9c2444db29d3053228ac84cca3e5f28335a3 /clang/unittests/Format
parent187ffb4a8e13dafb90b7f371325065d0d648a4a1 (diff)
downloadbcm5719-llvm-7eb7507aeb3552400c8a1f4dc82bb2212260c0da.tar.gz
bcm5719-llvm-7eb7507aeb3552400c8a1f4dc82bb2212260c0da.zip
clang-format: fix fallback style set to "none" not always formatting
This fixes clang-format not formatting if fallback-style is explicitly set to "none", and either a config file is found or YAML is passed in without a "BasedOnStyle". With this change, passing "none" in these cases will have no affect, and LLVM style will be used as the base style. Differential Revision: https://reviews.llvm.org/D28844 llvm-svn: 292562
Diffstat (limited to 'clang/unittests/Format')
-rw-r--r--clang/unittests/Format/FormatTest.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 38095402f0c..a7c2f7c9df2 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -10978,13 +10978,31 @@ TEST(FormatStyle, GetStyleOfFile) {
ASSERT_TRUE((bool)Style1);
ASSERT_EQ(*Style1, getLLVMStyle());
- // Test 2: fallback to default.
+ // Test 2.1: fallback to default.
ASSERT_TRUE(
FS.addFile("/b/test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("int i;")));
auto Style2 = getStyle("file", "/b/test.cpp", "Mozilla", "", &FS);
ASSERT_TRUE((bool)Style2);
ASSERT_EQ(*Style2, getMozillaStyle());
+ // Test 2.2: no format on 'none' fallback style.
+ Style2 = getStyle("file", "/b/test.cpp", "none", "", &FS);
+ ASSERT_TRUE((bool)Style2);
+ ASSERT_EQ(*Style2, getNoStyle());
+
+ // Test 2.3: format if config is found with no based style while fallback is
+ // 'none'.
+ ASSERT_TRUE(FS.addFile("/b/.clang-format", 0,
+ llvm::MemoryBuffer::getMemBuffer("IndentWidth: 2")));
+ Style2 = getStyle("file", "/b/test.cpp", "none", "", &FS);
+ ASSERT_TRUE((bool)Style2);
+ ASSERT_EQ(*Style2, getLLVMStyle());
+
+ // Test 2.4: format if yaml with no based style, while fallback is 'none'.
+ Style2 = getStyle("{}", "a.h", "none", "", &FS);
+ ASSERT_TRUE((bool)Style2);
+ ASSERT_EQ(*Style2, getLLVMStyle());
+
// Test 3: format file in parent directory.
ASSERT_TRUE(
FS.addFile("/c/.clang-format", 0,
OpenPOWER on IntegriCloud