blob: ba06babee35a80049e7fa97c7ce7ab9044cf90ef [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
Kuba Mracek5b576332017-08-15 19:47:06 +00005// 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
Nico Weber3cb667e2015-10-19 16:21:29 +000013// 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
Antonio Maiorano7eb75072017-01-20 01:22:42 +000015
16// Fallback style tests
Antonio Maiorano7eb75072017-01-20 01:22:42 +000017// Test config file with no based style, and fallback style "none", formatting is applied
Kuba Mracek5b576332017-08-15 19:47:06 +000018// 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
Antonio Maiorano7eb75072017-01-20 01:22:42 +000020// Test yaml with no based style, and fallback style "none", LLVM formatting applied
Antonio Maioranoae834042017-01-23 13:20:23 +000021// RUN: clang-format -style="{IndentWidth: 7}" -fallback-style=none %s | FileCheck -strict-whitespace -check-prefix=CHECK11 %s
Antonio Maiorano7eb75072017-01-20 01:22:42 +000022
Alexander Kornienko006b5c82013-05-19 00:53:30 +000023void f() {
24// CHECK1: {{^ int\* i;$}}
25// CHECK2: {{^ int \*i;$}}
26// CHECK3: Unknown value for BasedOnStyle: invalid
Antonio Maiorano3adfb6a2017-01-17 00:12:27 +000027// CHECK3: Error parsing -style: {{I|i}}nvalid argument
28// CHECK4: Error parsing -style: {{I|i}}nvalid argument
Chandler Carruthbc36e6e02013-09-02 07:42:02 +000029// CHECK5: {{^ int\* i;$}}
Rafael Espindola374597a2014-06-12 12:40:04 +000030// CHECK6: {{^Error reading .*\.clang-format: (I|i)nvalid argument}}
Hans Wennborg9f6581b2013-09-10 15:41:12 +000031// CHECK7: {{^ int\* i;$}}
Daniel Jasper553d4872014-06-17 12:40:34 +000032// CHECK8: {{^ int\* i;$}}
33// CHECK9: {{^ int \*i;$}}
Antonio Maioranoae834042017-01-23 13:20:23 +000034// CHECK10: {{^ int \*i;$}}
35// CHECK11: {{^ int \*i;$}}
Alexander Kornienko006b5c82013-05-19 00:53:30 +000036int*i;
37int j;
38}
Reid Klecknerf8439942015-06-09 17:47:59 +000039
40// On Windows, the 'rm' commands fail when the previous process is still alive.
41// This happens enough to make the test useless.
Reid Kleckner38e033b2019-09-10 20:15:45 +000042// UNSUPPORTED: system-windows