53 lines · cpp
1// RUN: clang-format -style="{BasedOnStyle: Google, IndentWidth: 8}" %s | FileCheck -strict-whitespace -check-prefix=CHECK1 %s2// RUN: clang-format -style="{BasedOnStyle: LLVM, IndentWidth: 7}" %s | FileCheck -strict-whitespace -check-prefix=CHECK2 %s3// RUN: not clang-format -style="{BasedOnStyle: invalid, IndentWidth: 7}" -fallback-style=LLVM %s 2>&1 | FileCheck -DMSG=%errc_EINVAL -strict-whitespace -check-prefix=CHECK3 %s4// RUN: not clang-format -style="{lsjd}" %s -fallback-style=LLVM 2>&1 | FileCheck -DMSG=%errc_EINVAL -strict-whitespace -check-prefix=CHECK4 %s5// RUN: mkdir -p %t6// RUN: printf "BasedOnStyle: google\nIndentWidth: 5\n" > %t/.clang-format7// RUN: clang-format -style=file -assume-filename=%t/foo.cpp < %s | FileCheck -strict-whitespace -check-prefix=CHECK5 %s8// RUN: printf "Invalid:\n" > %t/.clang-format9// RUN: not clang-format -style=file -fallback-style=webkit -assume-filename=%t/foo.cpp < %s 2>&1 | FileCheck -DMSG=%errc_EINVAL -strict-whitespace -check-prefix=CHECK6 %s10// RUN: rm %t/.clang-format11// RUN: printf "BasedOnStyle: google\nIndentWidth: 6\n" > %t/_clang-format12// RUN: clang-format -style=file -assume-filename=%t/foo.cpp < %s | FileCheck -strict-whitespace -check-prefix=CHECK7 %s13// RUN: clang-format -style="{BasedOnStyle: LLVM, PointerBindsToType: true}" %s | FileCheck -strict-whitespace -check-prefix=CHECK8 %s14// RUN: clang-format -style="{BasedOnStyle: WebKit, PointerBindsToType: false}" %s | FileCheck -strict-whitespace -check-prefix=CHECK9 %s15 16// Fallback style tests17// Test config file with no based style, and fallback style "none", formatting is applied18// RUN: printf "IndentWidth: 6\n" > %t/_clang-format19// RUN: clang-format -style=file -fallback-style=none -assume-filename=%t/foo.cpp < %s 2>&1 | FileCheck -strict-whitespace -check-prefix=CHECK10 %s20// Test yaml with no based style, and fallback style "none", LLVM formatting applied21// RUN: clang-format -style="{IndentWidth: 7}" -fallback-style=none %s | FileCheck -strict-whitespace -check-prefix=CHECK11 %s22 23// Empty config file tests24// RUN: touch %t/.clang-format25// RUN: clang-format -style=file -assume-filename=%t/foo.cpp < %s | FileCheck -strict-whitespace -check-prefix=CHECK12 %s26// RUN: rm %t/.clang-format27// RUN: printf "\n" > %t/_clang-format28// RUN: clang-format -style=file -assume-filename=%t/foo.cpp < %s | FileCheck -strict-whitespace -check-prefix=CHECK13 %s29 30void f() {31// CHECK1: {{^ int\* i;$}}32// CHECK2: {{^ int \*i;$}}33// CHECK3: Unknown value for BasedOnStyle: invalid34// CHECK3: Error parsing -style: [[MSG]]35// CHECK4: Error parsing -style: [[MSG]]36// CHECK5: {{^ int\* i;$}}37// CHECK6: unknown key 'Invalid'38// CHECK6: {{^Error reading .*\.clang-format:}} [[MSG]]39// CHECK7: {{^ int\* i;$}}40// CHECK8: {{^ int\* i;$}}41// CHECK9: {{^ int \*i;$}}42// CHECK10: {{^ int \*i;$}}43// CHECK11: {{^ int \*i;$}}44// CHECK12: {{^ int \*i;$}}45// CHECK13: {{^ int \*i;$}}46int*i;47int j;48}49 50// On Windows, the 'rm' commands fail when the previous process is still alive.51// This happens enough to make the test useless.52// UNSUPPORTED: system-windows53