style-on-command-line.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. // RUN: grep -Ev "// *[A-Z0-9_]+:" %s > %t.cpp
  2. // RUN: clang-format -style="{BasedOnStyle: Google, IndentWidth: 8}" %t.cpp | FileCheck -strict-whitespace -check-prefix=CHECK1 %s
  3. // RUN: clang-format -style="{BasedOnStyle: LLVM, IndentWidth: 7}" %t.cpp | FileCheck -strict-whitespace -check-prefix=CHECK2 %s
  4. // RUN: clang-format -style="{BasedOnStyle: invalid, IndentWidth: 7}" -fallback-style=LLVM %t.cpp 2>&1 | FileCheck -strict-whitespace -check-prefix=CHECK3 %s
  5. // RUN: clang-format -style="{lsjd}" %t.cpp -fallback-style=LLVM 2>&1 | FileCheck -strict-whitespace -check-prefix=CHECK4 %s
  6. // RUN: printf "BasedOnStyle: google\nIndentWidth: 5\n" > %T/.clang-format
  7. // RUN: clang-format -style=file %t.cpp 2>&1 | FileCheck -strict-whitespace -check-prefix=CHECK5 %s
  8. // RUN: printf "\n" > %T/.clang-format
  9. // RUN: clang-format -style=file -fallback-style=webkit %t.cpp 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 %t.cpp 2>&1 | FileCheck -strict-whitespace -check-prefix=CHECK7 %s
  13. // RUN: clang-format -style="{BasedOnStyle: LLVM, PointerBindsToType: true}" %t.cpp | FileCheck -strict-whitespace -check-prefix=CHECK8 %s
  14. // RUN: clang-format -style="{BasedOnStyle: WebKit, PointerBindsToType: false}" %t.cpp | FileCheck -strict-whitespace -check-prefix=CHECK9 %s
  15. void f() {
  16. // CHECK1: {{^ int\* i;$}}
  17. // CHECK2: {{^ int \*i;$}}
  18. // CHECK3: Unknown value for BasedOnStyle: invalid
  19. // CHECK3: Error parsing -style: {{I|i}}nvalid argument, using LLVM style
  20. // CHECK3: {{^ int \*i;$}}
  21. // CHECK4: Error parsing -style: {{I|i}}nvalid argument, using LLVM style
  22. // CHECK4: {{^ int \*i;$}}
  23. // CHECK5: {{^ int\* i;$}}
  24. // CHECK6: {{^Error reading .*\.clang-format: (I|i)nvalid argument}}
  25. // CHECK6: {{^ int\* i;$}}
  26. // CHECK7: {{^ int\* i;$}}
  27. // CHECK8: {{^ int\* i;$}}
  28. // CHECK9: {{^ int \*i;$}}
  29. int*i;
  30. int j;
  31. }
  32. // On Windows, the 'rm' commands fail when the previous process is still alive.
  33. // This happens enough to make the test useless.
  34. // REQUIRES: shell