fix: harden bun_test launcher args and test metadata

This commit is contained in:
Eric
2026-03-04 03:22:58 +00:00
parent 42469425e1
commit 861a677582
4 changed files with 13 additions and 6 deletions

View File

@@ -1,11 +1,15 @@
"""Rule for running test suites with Bun."""
def _shell_quote(value):
return "'" + value.replace("'", "'\"'\"'") + "'"
def _bun_test_impl(ctx):
toolchain = ctx.toolchains["//bun:toolchain_type"]
bun_bin = toolchain.bun.bun_bin
src_args = " ".join(["\"{}\"".format(src.path) for src in ctx.files.srcs])
src_args = " ".join([_shell_quote(src.path) for src in ctx.files.srcs])
launcher = ctx.actions.declare_file(ctx.label.name)
ctx.actions.write(
output = launcher,
@@ -20,9 +24,11 @@ fi
if [[ -n "${{COVERAGE_DIR:-}}" ]]; then
extra_args+=("--coverage")
fi
exec "{}" test {} "${{extra_args[@]}}" "$@"
""".format(bun_bin.path, src_args),
exec "{bun_bin}" test {src_args} "${{extra_args[@]}}" "$@"
""".format(
bun_bin = bun_bin.path,
src_args = src_args,
),
)
transitive_files = []

View File

@@ -12,6 +12,7 @@ bun_test(
bun_test(
name = "failing_suite",
srcs = ["failing.test.ts"],
tags = ["manual"],
target_compatible_with = [
"@platforms//cpu:x86_64",
"@platforms//os:linux",

View File

@@ -1,5 +1,5 @@
import { expect, test } from "bun:test";
test("failing suite", () => {
test("intentionally fails for manual validation", () => {
expect(1 + 1).toBe(3);
});

View File

@@ -1,5 +1,5 @@
import { expect, test } from "bun:test";
test("passing suite", () => {
test("adds two numbers correctly", () => {
expect(1 + 1).toBe(2);
});