blob: b2724353da134b2b954fcccfcf32c0428075a232 [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
Antonio Maiorano7eb75072017-01-20 01:22:42 +000016// Test config file with no based style, and fallback style "none", formatting is applied
17// RUN: printf "IndentWidth: 6\n" > %T/_clang-format
Antonio Maioranoae834042017-01-23 13:20:23 +000018// RUN: clang-format -style=file -fallback-style=none -assume-filename=%T/foo.cpp < %s 2>&1 | FileCheck -strict-whitespace -check-prefix=CHECK10 %s
Antonio Maiorano7eb75072017-01-20 01:22:42 +000019// Test yaml with no based style, and fallback style "none", LLVM formatting applied
Antonio Maioranoae834042017-01-23 13:20:23 +000020// RUN: clang-format -style="{IndentWidth: 7}" -fallback-style=none %s | FileCheck -strict-whitespace -check-prefix=CHECK11 %s
Antonio Maiorano7eb75072017-01-20 01:22:42 +000021
Alexander Kornienko006b5c82013-05-19 00:53:30 +000022void f() {
23// CHECK1: {{^ int\* i;$}}
24// CHECK2: {{^ int \*i;$}}
25// CHECK3: Unknown value for BasedOnStyle: invalid
Antonio Maiorano3adfb6a2017-01-17 00:12:27 +000026// CHECK3: Error parsing -style: {{I|i}}nvalid argument
27// CHECK4: Error parsing -style: {{I|i}}nvalid argument
Chandler Carruthbc36e6e02013-09-02 07:42:02 +000028// CHECK5: {{^ int\* i;$}}
Rafael Espindola374597a2014-06-12 12:40:04 +000029// CHECK6: {{^Error reading .*\.clang-format: (I|i)nvalid argument}}
Hans Wennborg9f6581b2013-09-10 15:41:12 +000030// CHECK7: {{^ int\* i;$}}
Daniel Jasper553d4872014-06-17 12:40:34 +000031// CHECK8: {{^ int\* i;$}}
32// CHECK9: {{^ int \*i;$}}
Antonio Maioranoae834042017-01-23 13:20:23 +000033// CHECK10: {{^ int \*i;$}}
34// CHECK11: {{^ int \*i;$}}
Alexander Kornienko006b5c82013-05-19 00:53:30 +000035int*i;
36int j;
37}
Reid Klecknerf8439942015-06-09 17:47:59 +000038
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