|
| 1 | +# Simple test fixture that uses this "real" git repository. |
| 2 | +# Ideally we would create self-contained "system under test" for each test case. |
| 3 | +# That would let us test more scenarios with git, like deleted files. |
| 4 | +bats_load_library "bats-support" |
| 5 | +bats_load_library "bats-assert" |
| 6 | + |
| 7 | +# No arguments: will use git ls-files |
| 8 | +@test "should run prettier on javascript using git ls-files" { |
| 9 | + run bazel run //format/test:format_javascript |
| 10 | + assert_success |
| 11 | + |
| 12 | + assert_output --partial "Formatting JavaScript with Prettier..." |
| 13 | + assert_output --partial "+ prettier --write example/.eslintrc.cjs" |
| 14 | + assert_output --partial "Formatting TypeScript with Prettier..." |
| 15 | + assert_output --partial "+ prettier --write example/src/file.ts example/test/no_violations.ts" |
| 16 | + assert_output --partial "Formatting TSX with Prettier..." |
| 17 | + assert_output --partial "+ prettier --write example/src/hello.tsx" |
| 18 | + assert_output --partial "Formatting JSON with Prettier..." |
| 19 | + assert_output --partial "+ prettier --write renovate.json" |
| 20 | + assert_output --partial "Formatting CSS with Prettier..." |
| 21 | + assert_output --partial "+ prettier --write example/src/hello.css" |
| 22 | + assert_output --partial "Formatting HTML with Prettier..." |
| 23 | + assert_output --partial "+ prettier --write example/src/index.html" |
| 24 | +} |
| 25 | + |
| 26 | +# File arguments: will filter with find |
| 27 | +@test "should run prettier on javascript using find" { |
| 28 | + run bazel run //format/test:format_javascript README.md example/.eslintrc.cjs |
| 29 | + assert_success |
| 30 | + |
| 31 | + assert_output --partial "Formatting JavaScript with Prettier..." |
| 32 | + refute_output --partial "Formatting TypeScript with Prettier..." |
| 33 | +} |
| 34 | + |
| 35 | +@test "should run buildozer on starlark" { |
| 36 | + run bazel run //format/test:format_starlark |
| 37 | + assert_success |
| 38 | + |
| 39 | + assert_output --partial "Formatting Starlark with Buildifier..." |
| 40 | + assert_output --partial "+ buildifier -mode=fix BUILD.bazel" |
| 41 | + # FIXME(#122): this was broken by #105 |
| 42 | + # assert_output --partial "format/private/BUILD.bazel" |
| 43 | +} |
| 44 | + |
| 45 | +@test "should run prettier on Markdown" { |
| 46 | + run bazel run //format/test:format_markdown |
| 47 | + assert_success |
| 48 | + |
| 49 | + assert_output --partial "Formatting Markdown with Prettier..." |
| 50 | + assert_output --partial "+ prettier --write CONTRIBUTING.md README.md" |
| 51 | +} |
| 52 | + |
| 53 | +@test "should run prettier on SQL" { |
| 54 | + run bazel run //format/test:format_sql |
| 55 | + assert_success |
| 56 | + |
| 57 | + assert_output --partial "Formatting SQL with Prettier..." |
| 58 | + assert_output --partial "+ prettier --write example/src/hello.sql" |
| 59 | +} |
| 60 | + |
| 61 | +@test "should run ruff on Python" { |
| 62 | + run bazel run //format/test:format_python |
| 63 | + assert_success |
| 64 | + |
| 65 | + assert_output --partial "Formatting Python with Ruff..." |
| 66 | + assert_output --partial "+ ruff format --force-exclude example/src/subdir/unused_import.py" |
| 67 | +} |
| 68 | + |
| 69 | +@test "should run terraform fmt on HCL" { |
| 70 | + run bazel run //format/test:format_hcl |
| 71 | + assert_success |
| 72 | + |
| 73 | + assert_output --partial "Formatting Hashicorp Config Language with terraform fmt..." |
| 74 | + assert_output --partial "+ terraform-fmt fmt example/src/hello.tf" |
| 75 | +} |
| 76 | + |
| 77 | +@test "should run jsonnet-fmt on Jsonnet" { |
| 78 | + run bazel run //format/test:format_jsonnet |
| 79 | + assert_success |
| 80 | + |
| 81 | + assert_output --partial "Formatting Jsonnet with jsonnetfmt..." |
| 82 | + assert_output --partial "+ jsonnetfmt --in-place example/src/hello.jsonnet example/src/hello.libsonnet" |
| 83 | +} |
| 84 | + |
| 85 | +@test "should run java-format on Java" { |
| 86 | + run bazel run //format/test:format_java |
| 87 | + assert_success |
| 88 | + |
| 89 | + assert_output --partial "Formatting Java with java-format..." |
| 90 | + assert_output --partial "+ java-format --replace example/src/Foo.java" |
| 91 | +} |
| 92 | + |
| 93 | +@test "should run ktfmt on Kotlin" { |
| 94 | + run bazel run //format/test:format_kotlin |
| 95 | + assert_success |
| 96 | + |
| 97 | + assert_output --partial "Formatting Kotlin with ktfmt..." |
| 98 | + assert_output --partial "+ ktfmt example/src/hello.kt" |
| 99 | +} |
| 100 | + |
| 101 | +@test "should run scalafmt on Scala" { |
| 102 | + run bazel run //format/test:format_scala |
| 103 | + assert_success |
| 104 | + |
| 105 | + assert_output --partial "Formatting Scala with scalafmt..." |
| 106 | + assert_output --partial "+ scalafmt example/src/hello.scala" |
| 107 | +} |
| 108 | + |
| 109 | +@test "should run gofmt on Go" { |
| 110 | + run bazel run //format/test:format_go |
| 111 | + assert_success |
| 112 | + |
| 113 | + assert_output --partial "Formatting Go with gofmt..." |
| 114 | + assert_output --partial "+ gofmt -w example/src/hello.go" |
| 115 | +} |
| 116 | + |
| 117 | +@test "should run clang-format on C++" { |
| 118 | + run bazel run //format/test:format_cc |
| 119 | + assert_success |
| 120 | + |
| 121 | + assert_output --partial "Formatting C/C++ with clang-format..." |
| 122 | + assert_output --partial "+ clang-format -style=file --fallback-style=none -i example/src/hello.cpp" |
| 123 | +} |
| 124 | + |
| 125 | +@test "should run shfmt on Shell" { |
| 126 | + run bazel run //format/test:format_sh |
| 127 | + assert_success |
| 128 | + |
| 129 | + assert_output --partial "Formatting Shell with shfmt..." |
| 130 | + assert_output --partial "+ shfmt -w .github/workflows/release_prep.sh" |
| 131 | +} |
| 132 | + |
| 133 | +@test "should run swiftformat on Swift" { |
| 134 | + run bazel run //format/test:format_swift |
| 135 | + assert_success |
| 136 | + |
| 137 | + # The real swiftformat prints the "Formatting..." output so we don't |
| 138 | + assert_output --partial "+ swiftformat example/src/hello.swift" |
| 139 | +} |
| 140 | + |
| 141 | +@test "should run buf on Protobuf" { |
| 142 | + run bazel run //format/test:format_protobuf |
| 143 | + assert_success |
| 144 | + |
| 145 | + assert_output --partial "Formatting Protobuf with buf..." |
| 146 | + # Buf only formats one file at a time |
| 147 | + assert_output --partial "+ buf format -w example/src/file.proto" |
| 148 | + assert_output --partial "+ buf format -w example/src/unused.proto" |
| 149 | +} |
0 commit comments