aboutsummaryrefslogtreecommitdiff
path: root/src/cli.zig
diff options
context:
space:
mode:
authorGravatar dave caruso <me@paperdave.net> 2023-08-06 06:13:39 -0700
committerGravatar GitHub <noreply@github.com> 2023-08-06 06:13:39 -0700
commitcd0774cd89f44ae3880ae5d3840787012d9df603 (patch)
treeb1285dd26a5134b227f56afcc58c8e2b519fd3a1 /src/cli.zig
parentcf8650937aa03b7410c24675868eec36b7e2f390 (diff)
downloadbun-cd0774cd89f44ae3880ae5d3840787012d9df603.tar.gz
bun-cd0774cd89f44ae3880ae5d3840787012d9df603.tar.zst
bun-cd0774cd89f44ae3880ae5d3840787012d9df603.zip
Implement --test-name-pattern (#3998)
* Fix end not being emitted all the time * stuff * Implement -t * Undo js_printer changes * Undo http changes * Update InternalModuleRegistryConstants.h * Delete unrelated test --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/cli.zig')
-rw-r--r--src/cli.zig23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/cli.zig b/src/cli.zig
index d19ede800..aa36c63fb 100644
--- a/src/cli.zig
+++ b/src/cli.zig
@@ -20,6 +20,7 @@ const json_parser = bun.JSON;
const js_printer = bun.js_printer;
const js_ast = bun.JSAst;
const linker = @import("linker.zig");
+const RegularExpression = bun.RegularExpression;
const sync = @import("./sync.zig");
const Api = @import("api/schema.zig").Api;
@@ -219,6 +220,7 @@ pub const Arguments = struct {
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,
+ clap.parseParam("-t, --test-name-pattern <STR> Run only tests with a name that matches the given regex.") catch unreachable,
};
const build_params_public = public_params ++ build_only_params;
@@ -388,12 +390,12 @@ pub const Arguments = struct {
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)});
+ Output.prettyErrorln("<r><red>error<r>: --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", .{});
+ Output.prettyErrorln("<r><red>error<r>: --bail expects a number greater than 0", .{});
Global.exit(1);
}
} else {
@@ -403,11 +405,25 @@ pub const Arguments = struct {
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| {
- Output.prettyErrorln("--rerun-each expects a number: {s}", .{@errorName(e)});
+ Output.prettyErrorln("<r><red>error<r>: --rerun-each expects a number: {s}", .{@errorName(e)});
Global.exit(1);
};
}
}
+ if (args.option("--test-name-pattern")) |namePattern| {
+ const regex = RegularExpression.init(bun.String.fromBytes(namePattern), RegularExpression.Flags.none) catch {
+ Output.prettyErrorln(
+ "<r><red>error<r>: --test-name-pattern expects a valid regular expression but received {}",
+ .{
+ strings.QuotedFormatter{
+ .text = namePattern,
+ },
+ },
+ );
+ Global.exit(1);
+ };
+ ctx.test_options.test_filter_regex = regex;
+ }
ctx.test_options.update_snapshots = args.flag("--update-snapshots");
ctx.test_options.run_todo = args.flag("--todo");
ctx.test_options.only = args.flag("--only");
@@ -949,6 +965,7 @@ pub const Command = struct {
run_todo: bool = false,
only: bool = false,
bail: u32 = 0,
+ test_filter_regex: ?*RegularExpression = null,
};
pub const Context = struct {