1 // RUN: clang-format -style="{BasedOnStyle: Google, IndentWidth: 8}" %s | FileCheck -strict-whitespace -check-prefix=CHECK1 %s
2 // RUN: clang-format -style="{BasedOnStyle: LLVM, IndentWidth: 7}" %s | FileCheck -strict-whitespace -check-prefix=CHECK2 %s
3 // RUN: not clang-format -style="{BasedOnStyle: invalid, IndentWidth: 7}" -fallback-style=LLVM %s 2>&1 | FileCheck -strict-whitespace -check-prefix=CHECK3 %s
4 // RUN: not clang-format -style="{lsjd}" %s -fallback-style=LLVM 2>&1 | FileCheck -strict-whitespace -check-prefix=CHECK4 %s
5 // RUN: printf "BasedOnStyle: google\nIndentWidth: 5\n" > %T/.clang-format
6 // RUN: clang-format -style=file -assume-filename=%T/foo.cpp < %s | FileCheck -strict-whitespace -check-prefix=CHECK5 %s
7 // RUN: printf "\n" > %T/.clang-format
8 // RUN: not clang-format -style=file -fallback-style=webkit -assume-filename=%T/foo.cpp < %s 2>&1 | FileCheck -strict-whitespace -check-prefix=CHECK6 %s
9 // RUN: rm %T/.clang-format
10 // RUN: printf "BasedOnStyle: google\nIndentWidth: 6\n" > %T/_clang-format
11 // RUN: clang-format -style=file -assume-filename=%T/foo.cpp < %s | FileCheck -strict-whitespace -check-prefix=CHECK7 %s
12 // RUN: clang-format -style="{BasedOnStyle: LLVM, PointerBindsToType: true}" %s | FileCheck -strict-whitespace -check-prefix=CHECK8 %s
13 // RUN: clang-format -style="{BasedOnStyle: WebKit, PointerBindsToType: false}" %s | FileCheck -strict-whitespace -check-prefix=CHECK9 %s
14 
15 // Fallback style tests
16 // Test config file with no based style, and fallback style "none", formatting is applied
17 // RUN: printf "IndentWidth: 6\n" > %T/_clang-format
18 // RUN: clang-format -style=file -fallback-style=none -assume-filename=%T/foo.cpp < %s 2>&1 | FileCheck -strict-whitespace -check-prefix=CHECK10 %s
19 // Test yaml with no based style, and fallback style "none", LLVM formatting applied
20 // RUN: clang-format -style="{IndentWidth: 7}" -fallback-style=none %s | FileCheck -strict-whitespace -check-prefix=CHECK11 %s
21 
22 void f() {
23 // CHECK1: {{^        int\* i;$}}
24 // CHECK2: {{^       int \*i;$}}
25 // CHECK3: Unknown value for BasedOnStyle: invalid
26 // CHECK3: Error parsing -style: {{I|i}}nvalid argument
27 // CHECK4: Error parsing -style: {{I|i}}nvalid argument
28 // CHECK5: {{^     int\* i;$}}
29 // CHECK6: {{^Error reading .*\.clang-format: (I|i)nvalid argument}}
30 // CHECK7: {{^      int\* i;$}}
31 // CHECK8: {{^  int\* i;$}}
32 // CHECK9: {{^    int \*i;$}}
33 // CHECK10: {{^      int \*i;$}}
34 // CHECK11: {{^       int \*i;$}}
35 int*i;
36 int j;
37 }
38 
39 // On Windows, the 'rm' commands fail when the previous process is still alive.
40 // This happens enough to make the test useless.
41 // REQUIRES: shell
42