blob: d6ab41f5751aee35e1afd80e294007d02f14aba4 [file] [log] [blame]
Nico Weber3cb667e2015-10-19 16:21:29 +00001// 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 Maiorano3adfb6a2017-01-17 00:12:27 +00003// 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 Dunbar14e88a12013-08-29 03:02:39 +00005// RUN: printf "BasedOnStyle: google\nIndentWidth: 5\n" > %T/.clang-format
Nico Weber3cb667e2015-10-19 16:21:29 +00006// RUN: clang-format -style=file -assume-filename=%T/foo.cpp < %s | FileCheck -strict-whitespace -check-prefix=CHECK5 %s
Alexander Kornienko9acf3db2013-09-02 13:44:16 +00007// RUN: printf "\n" > %T/.clang-format
Antonio Maiorano3adfb6a2017-01-17 00:12:27 +00008// 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 Kramerfea47d42015-06-09 12:41:02 +00009// RUN: rm %T/.clang-format
Hans Wennborg9f6581b2013-09-10 15:41:12 +000010// RUN: printf "BasedOnStyle: google\nIndentWidth: 6\n" > %T/_clang-format
Nico Weber3cb667e2015-10-19 16:21:29 +000011// 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 Maiorano7eb75072017-01-20 01:22:42 +000014
15// Fallback style tests
16// RUN: rm %T/_clang-format
17// Test no config file found, WebKit fallback style is applied
18// RUN: clang-format -style=file -fallback-style=WebKit -assume-filename=%T/foo.cpp < %s 2>&1 | FileCheck -strict-whitespace -check-prefix=CHECK10 %s
Antonio Maiorano7eb75072017-01-20 01:22:42 +000019// Test no config file and fallback style "none", no formatting is applied
Krasimir Georgiev69cb6ce2017-01-20 12:39:05 +000020// RUN: clang-format -style=file -fallback-style=none -assume-filename=%T/foo.cpp < %s 2>&1 | FileCheck -strict-whitespace -check-prefix=CHECK11 %s
Antonio Maiorano7eb75072017-01-20 01:22:42 +000021// Test config file with no based style, and fallback style "none", formatting is applied
22// RUN: printf "IndentWidth: 6\n" > %T/_clang-format
Krasimir Georgiev69cb6ce2017-01-20 12:39:05 +000023// RUN: clang-format -style=file -fallback-style=none -assume-filename=%T/foo.cpp < %s 2>&1 | FileCheck -strict-whitespace -check-prefix=CHECK12 %s
Antonio Maiorano7eb75072017-01-20 01:22:42 +000024// Test yaml with no based style, and fallback style "none", LLVM formatting applied
Krasimir Georgiev69cb6ce2017-01-20 12:39:05 +000025// RUN: clang-format -style="{IndentWidth: 7}" -fallback-style=none %s | FileCheck -strict-whitespace -check-prefix=CHECK13 %s
Antonio Maiorano7eb75072017-01-20 01:22:42 +000026
Alexander Kornienko006b5c82013-05-19 00:53:30 +000027void f() {
28// CHECK1: {{^ int\* i;$}}
29// CHECK2: {{^ int \*i;$}}
30// CHECK3: Unknown value for BasedOnStyle: invalid
Antonio Maiorano3adfb6a2017-01-17 00:12:27 +000031// CHECK3: Error parsing -style: {{I|i}}nvalid argument
32// CHECK4: Error parsing -style: {{I|i}}nvalid argument
Chandler Carruthbc36e6e02013-09-02 07:42:02 +000033// CHECK5: {{^ int\* i;$}}
Rafael Espindola374597a2014-06-12 12:40:04 +000034// CHECK6: {{^Error reading .*\.clang-format: (I|i)nvalid argument}}
Hans Wennborg9f6581b2013-09-10 15:41:12 +000035// CHECK7: {{^ int\* i;$}}
Daniel Jasper553d4872014-06-17 12:40:34 +000036// CHECK8: {{^ int\* i;$}}
37// CHECK9: {{^ int \*i;$}}
Antonio Maiorano7eb75072017-01-20 01:22:42 +000038// CHECK10: {{^ int\* i;$}}
Krasimir Georgiev69cb6ce2017-01-20 12:39:05 +000039// CHECK11: {{^int\*i;$}}
40// CHECK12: {{^ int \*i;$}}
41// CHECK13: {{^ int \*i;$}}
Alexander Kornienko006b5c82013-05-19 00:53:30 +000042int*i;
43int j;
44}
Reid Klecknerf8439942015-06-09 17:47:59 +000045
46// On Windows, the 'rm' commands fail when the previous process is still alive.
47// This happens enough to make the test useless.
48// REQUIRES: shell