aboutsummaryrefslogtreecommitdiff
path: root/src/cli.zig
diff options
context:
space:
mode:
authorGravatar Tiramify (A.K. Daniel) <94789999+TiranexDev@users.noreply.github.com> 2023-07-12 22:41:46 +0200
committerGravatar GitHub <noreply@github.com> 2023-07-12 13:41:46 -0700
commit0631f878667d9a5cab80d7c1167eac7cbc1c93c6 (patch)
tree347e18a9774fb9b699596805e477c96c19b9c819 /src/cli.zig
parent4e1a81231c868bb090d627bacebb3c2f10e877ef (diff)
downloadbun-0631f878667d9a5cab80d7c1167eac7cbc1c93c6.tar.gz
bun-0631f878667d9a5cab80d7c1167eac7cbc1c93c6.tar.zst
bun-0631f878667d9a5cab80d7c1167eac7cbc1c93c6.zip
feat(bun/test): Implement "bail" option for "bun test" (#3253)
* Implement bun test --bail * Fixes * move printSummary() (more readable) * Fixes 2 * idk why it got deleted * Fixes 3 * fmt this better * Update test_command.zig * Fix "0 files" * track number of files so bailing out early prints the right number --------- Co-authored-by: dave caruso <me@paperdave.net>
Diffstat (limited to 'src/cli.zig')
-rw-r--r--src/cli.zig19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/cli.zig b/src/cli.zig
index 3d0fb5b37..f0cc47918 100644
--- a/src/cli.zig
+++ b/src/cli.zig
@@ -217,6 +217,7 @@ pub const Arguments = struct {
clap.parseParam("--rerun-each <NUMBER> Re-run each test file <NUMBER> times, helps catch certain bugs") catch unreachable,
clap.parseParam("--only Only run tests that are marked with \"test.only()\"") catch unreachable,
clap.parseParam("--todo Include tests that are marked with \"test.todo()\"") catch unreachable,
+ clap.parseParam("--bail <NUMBER>? Exit the test suite after <NUMBER> failures. If you do not specify a number, it defaults to 1.") catch unreachable,
};
const build_params_public = public_params ++ build_only_params;
@@ -383,7 +384,21 @@ pub const Arguments = struct {
};
}
}
- ctx.test_options.update_snapshots = args.flag("--update-snapshots");
+ if (args.option("--bail")) |bail| {
+ if (bail.len > 0) {
+ ctx.test_options.bail = std.fmt.parseInt(u32, bail, 10) catch |e| {
+ Output.prettyErrorln("--bail expects a number: {s}", .{@errorName(e)});
+ Global.exit(1);
+ };
+
+ if (ctx.test_options.bail == 0) {
+ Output.prettyErrorln("--bail expects a number greater than 0", .{});
+ Global.exit(1);
+ }
+ } else {
+ ctx.test_options.bail = 1;
+ }
+ }
if (args.option("--rerun-each")) |repeat_count| {
if (repeat_count.len > 0) {
ctx.test_options.repeat_count = std.fmt.parseInt(u32, repeat_count, 10) catch |e| {
@@ -392,6 +407,7 @@ pub const Arguments = struct {
};
}
}
+ ctx.test_options.update_snapshots = args.flag("--update-snapshots");
ctx.test_options.run_todo = args.flag("--todo");
ctx.test_options.only = args.flag("--only");
}
@@ -929,6 +945,7 @@ pub const Command = struct {
repeat_count: u32 = 0,
run_todo: bool = false,
only: bool = false,
+ bail: u32 = 0,
};
pub const Context = struct {