generated from bazel-contrib/rules-template
-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: add test coverage for format binary
This is a beginning, if the pattern works I'll apply it to remaining languages. Should be able to catch most regressions this way.
- Loading branch information
Showing
5 changed files
with
83 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
load("@bazel_skylib//rules:write_file.bzl", "write_file") | ||
load("//format:defs.bzl", "multi_formatter_binary") | ||
load("//format/private:formatter_binary.bzl", "TOOLS") | ||
|
||
# Avoid depending on a bunch of actual tools in the root module. | ||
# That's the job of the example/ submodule. | ||
# Instead, just provide a tool that acts like any of the formatters we support. | ||
[ | ||
write_file( | ||
name = "fake_{}_sh".format(t), | ||
out = "fake_{}.sh".format(t), | ||
content = [ | ||
"#!/usr/bin/env bash", | ||
"echo + {} $*".format(t), | ||
], | ||
) | ||
for t in TOOLS.values() | ||
] | ||
|
||
[ | ||
sh_binary( | ||
name = "fake_" + t, | ||
srcs = ["fake_{}.sh".format(t)], | ||
) | ||
for t in TOOLS.values() | ||
] | ||
|
||
multi_formatter_binary( | ||
name = "format_javascript", | ||
javascript = ":fake_prettier", | ||
) | ||
|
||
multi_formatter_binary( | ||
name = "format_starlark", | ||
starlark = ":fake_buildifier", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
bats_load_library "bats-support" | ||
bats_load_library "bats-assert" | ||
|
||
@test "should run prettier on javascript" { | ||
run bazel run //format/test:format_javascript | ||
assert_success | ||
|
||
echo <<"EOF" | assert_output --partial | ||
Formatting JavaScript with Prettier... | ||
+ prettier --write example/.eslintrc.cjs | ||
EOF | ||
echo <<"EOF" | assert_output --partial | ||
Formatting TypeScript with Prettier... | ||
+ prettier --write example/src/file.ts example/test/no_violations.ts | ||
EOF | ||
echo <<"EOF" | assert_output --partial | ||
Formatting TSX with Prettier... | ||
+ prettier --write example/src/hello.tsx | ||
EOF | ||
} | ||
|
||
@test "should run buildozer on starlark" { | ||
run bazel run //format/test:format_starlark | ||
assert_success | ||
assert_output --partial "Formatting Starlark with Buildifier..." | ||
assert_output --partial "+ buildifier -mode=fix BUILD.bazel" | ||
assert_output --partial "format/private/BUILD.bazel" | ||
|
||
} |