Nico Weber | 3cb667e | 2015-10-19 16:21:29 +0000 | [diff] [blame] | 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 |
Antonio Maiorano | 3adfb6a | 2017-01-17 00:12:27 +0000 | [diff] [blame] | 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 |
Daniel Dunbar | 14e88a1 | 2013-08-29 03:02:39 +0000 | [diff] [blame] | 5 | // RUN: printf "BasedOnStyle: google\nIndentWidth: 5\n" > %T/.clang-format |
Nico Weber | 3cb667e | 2015-10-19 16:21:29 +0000 | [diff] [blame] | 6 | // RUN: clang-format -style=file -assume-filename=%T/foo.cpp < %s | FileCheck -strict-whitespace -check-prefix=CHECK5 %s |
Alexander Kornienko | 9acf3db | 2013-09-02 13:44:16 +0000 | [diff] [blame] | 7 | // RUN: printf "\n" > %T/.clang-format |
Antonio Maiorano | 3adfb6a | 2017-01-17 00:12:27 +0000 | [diff] [blame] | 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 |
Benjamin Kramer | fea47d4 | 2015-06-09 12:41:02 +0000 | [diff] [blame] | 9 | // RUN: rm %T/.clang-format |
Hans Wennborg | 9f6581b | 2013-09-10 15:41:12 +0000 | [diff] [blame] | 10 | // RUN: printf "BasedOnStyle: google\nIndentWidth: 6\n" > %T/_clang-format |
Nico Weber | 3cb667e | 2015-10-19 16:21:29 +0000 | [diff] [blame] | 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 |
Antonio Maiorano | 7eb7507 | 2017-01-20 01:22:42 +0000 | [diff] [blame] | 14 | |
| 15 | // Fallback style tests |
Antonio Maiorano | 7eb7507 | 2017-01-20 01:22:42 +0000 | [diff] [blame] | 16 | // Test config file with no based style, and fallback style "none", formatting is applied |
| 17 | // RUN: printf "IndentWidth: 6\n" > %T/_clang-format |
Antonio Maiorano | ae83404 | 2017-01-23 13:20:23 +0000 | [diff] [blame] | 18 | // RUN: clang-format -style=file -fallback-style=none -assume-filename=%T/foo.cpp < %s 2>&1 | FileCheck -strict-whitespace -check-prefix=CHECK10 %s |
Antonio Maiorano | 7eb7507 | 2017-01-20 01:22:42 +0000 | [diff] [blame] | 19 | // Test yaml with no based style, and fallback style "none", LLVM formatting applied |
Antonio Maiorano | ae83404 | 2017-01-23 13:20:23 +0000 | [diff] [blame] | 20 | // RUN: clang-format -style="{IndentWidth: 7}" -fallback-style=none %s | FileCheck -strict-whitespace -check-prefix=CHECK11 %s |
Antonio Maiorano | 7eb7507 | 2017-01-20 01:22:42 +0000 | [diff] [blame] | 21 | |
Alexander Kornienko | 006b5c8 | 2013-05-19 00:53:30 +0000 | [diff] [blame] | 22 | void f() { |
| 23 | // CHECK1: {{^ int\* i;$}} |
| 24 | // CHECK2: {{^ int \*i;$}} |
| 25 | // CHECK3: Unknown value for BasedOnStyle: invalid |
Antonio Maiorano | 3adfb6a | 2017-01-17 00:12:27 +0000 | [diff] [blame] | 26 | // CHECK3: Error parsing -style: {{I|i}}nvalid argument |
| 27 | // CHECK4: Error parsing -style: {{I|i}}nvalid argument |
Chandler Carruth | bc36e6e0 | 2013-09-02 07:42:02 +0000 | [diff] [blame] | 28 | // CHECK5: {{^ int\* i;$}} |
Rafael Espindola | 374597a | 2014-06-12 12:40:04 +0000 | [diff] [blame] | 29 | // CHECK6: {{^Error reading .*\.clang-format: (I|i)nvalid argument}} |
Hans Wennborg | 9f6581b | 2013-09-10 15:41:12 +0000 | [diff] [blame] | 30 | // CHECK7: {{^ int\* i;$}} |
Daniel Jasper | 553d487 | 2014-06-17 12:40:34 +0000 | [diff] [blame] | 31 | // CHECK8: {{^ int\* i;$}} |
| 32 | // CHECK9: {{^ int \*i;$}} |
Antonio Maiorano | ae83404 | 2017-01-23 13:20:23 +0000 | [diff] [blame] | 33 | // CHECK10: {{^ int \*i;$}} |
| 34 | // CHECK11: {{^ int \*i;$}} |
Alexander Kornienko | 006b5c8 | 2013-05-19 00:53:30 +0000 | [diff] [blame] | 35 | int*i; |
| 36 | int j; |
| 37 | } |
Reid Kleckner | f843994 | 2015-06-09 17:47:59 +0000 | [diff] [blame] | 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 |