diff --git a/cli/args/flags.rs b/cli/args/flags.rs index 4f6d8bdb8c..144d1a57b9 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -102,6 +102,7 @@ pub struct BenchFlags { pub filter: Option, pub json: bool, pub no_run: bool, + pub permit_no_files: bool, pub watch: Option, } @@ -1754,6 +1755,12 @@ If you specify a directory instead of a file, the path is expanded to all contai .help("Cache bench modules, but don't run benchmarks") .action(ArgAction::SetTrue), ) + .arg( + Arg::new("permit-no-files") + .long("permit-no-files") + .help("Don't return an error code if no bench files were found") + .action(ArgAction::SetTrue) + ) .arg(watch_arg(false)) .arg(watch_exclude_arg()) .arg(no_clear_screen_arg()) @@ -4482,6 +4489,7 @@ fn bench_parse( flags.permissions.no_prompt = true; let json = matches.get_flag("json"); + let permit_no_files = matches.get_flag("permit-no-files"); let ignore = match matches.remove_many::("ignore") { Some(f) => f @@ -4511,6 +4519,7 @@ fn bench_parse( filter, json, no_run, + permit_no_files, watch: watch_arg_parse(matches)?, }); @@ -10804,6 +10813,7 @@ mod tests { ignore: vec![], }, watch: Default::default(), + permit_no_files: false, }), no_npm: true, no_remote: true, @@ -10835,6 +10845,34 @@ mod tests { ignore: vec![], }, watch: Some(Default::default()), + permit_no_files: false + }), + permissions: PermissionFlags { + no_prompt: true, + ..Default::default() + }, + type_check_mode: TypeCheckMode::Local, + ..Flags::default() + } + ); + } + + #[test] + fn bench_no_files() { + let r = flags_from_vec(svec!["deno", "bench", "--permit-no-files"]); + assert_eq!( + r.unwrap(), + Flags { + subcommand: DenoSubcommand::Bench(BenchFlags { + filter: None, + json: false, + no_run: false, + files: FileFlags { + include: vec![], + ignore: vec![], + }, + watch: None, + permit_no_files: true }), permissions: PermissionFlags { no_prompt: true, diff --git a/cli/args/mod.rs b/cli/args/mod.rs index 03ca2814a7..f0d59299d0 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -159,6 +159,7 @@ pub struct WorkspaceBenchOptions { pub filter: Option, pub json: bool, pub no_run: bool, + pub permit_no_files: bool, } impl WorkspaceBenchOptions { @@ -167,6 +168,7 @@ impl WorkspaceBenchOptions { filter: bench_flags.filter.clone(), json: bench_flags.json, no_run: bench_flags.no_run, + permit_no_files: bench_flags.permit_no_files, } } } diff --git a/cli/tools/bench/mod.rs b/cli/tools/bench/mod.rs index a316e60b52..0d8fb4750f 100644 --- a/cli/tools/bench/mod.rs +++ b/cli/tools/bench/mod.rs @@ -456,7 +456,7 @@ pub async fn run_benchmarks( .flatten() .collect::>(); - if specifiers.is_empty() { + if !workspace_bench_options.permit_no_files && specifiers.is_empty() { return Err(anyhow!("No bench modules found")); } diff --git a/tests/specs/bench/no_files/__test__.jsonc b/tests/specs/bench/no_files/__test__.jsonc new file mode 100644 index 0000000000..a58fad59e6 --- /dev/null +++ b/tests/specs/bench/no_files/__test__.jsonc @@ -0,0 +1,14 @@ +{ + "tests": { + "error": { + "args": "bench", + "output": "error.out", + "exitCode": 1 + }, + "permit_no_files": { + "args": "bench --permit-no-files", + "output": "", + "exitCode": 0 + } + } +} diff --git a/tests/specs/bench/no_files/error.out b/tests/specs/bench/no_files/error.out new file mode 100644 index 0000000000..186e371627 --- /dev/null +++ b/tests/specs/bench/no_files/error.out @@ -0,0 +1 @@ +error: No bench modules found