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