1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-11 08:33:43 -05:00

feat(bench): add --no-run flag (#18433)

This commit is contained in:
Geert-Jan Zwiers 2023-03-26 16:55:58 +02:00 committed by GitHub
parent 701099b2a9
commit a29d88b43b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 36 additions and 0 deletions

View file

@ -60,6 +60,7 @@ pub struct BenchFlags {
pub files: FileFlags,
pub filter: Option<String>,
pub json: bool,
pub no_run: bool,
}
#[derive(Clone, Debug, Eq, PartialEq)]
@ -804,6 +805,12 @@ fn bench_subcommand() -> Command {
.value_parser(value_parser!(PathBuf))
.action(ArgAction::Append),
)
.arg(
Arg::new("no-run")
.long("no-run")
.help("Cache bench modules, but don't run benchmarks")
.action(ArgAction::SetTrue),
)
.arg(watch_arg(false))
.arg(no_clear_screen_arg())
.arg(script_arg().last(true))
@ -2368,11 +2375,14 @@ fn bench_parse(flags: &mut Flags, matches: &mut ArgMatches) {
Vec::new()
};
let no_run = matches.get_flag("no-run");
watch_arg_parse(flags, matches, false);
flags.subcommand = DenoSubcommand::Bench(BenchFlags {
files: FileFlags { include, ignore },
filter,
json,
no_run,
});
}
@ -6482,6 +6492,7 @@ mod tests {
"--unstable",
"--no-npm",
"--no-remote",
"--no-run",
"--filter",
"- foo",
"--location",
@ -6499,6 +6510,7 @@ mod tests {
subcommand: DenoSubcommand::Bench(BenchFlags {
filter: Some("- foo".to_string()),
json: true,
no_run: true,
files: FileFlags {
include: vec![PathBuf::from("dir1/"), PathBuf::from("dir2/")],
ignore: vec![],
@ -6526,6 +6538,7 @@ mod tests {
subcommand: DenoSubcommand::Bench(BenchFlags {
filter: None,
json: false,
no_run: false,
files: FileFlags {
include: vec![],
ignore: vec![],

View file

@ -119,6 +119,7 @@ pub struct BenchOptions {
pub files: FilesConfig,
pub filter: Option<String>,
pub json: bool,
pub no_run: bool,
}
impl BenchOptions {
@ -134,6 +135,7 @@ impl BenchOptions {
),
filter: bench_flags.filter,
json: bench_flags.json,
no_run: bench_flags.no_run,
})
}
}

View file

@ -138,6 +138,12 @@ itest!(filter {
output: "bench/filter.out",
});
itest!(no_run {
args: "bench --no-run bench/no_run.ts",
output: "bench/no_run.out",
exit_code: 1,
});
itest!(no_prompt_by_default {
args: "bench --quiet bench/no_prompt_by_default.ts",
exit_code: 1,

5
cli/tests/testdata/bench/no_run.out vendored Normal file
View file

@ -0,0 +1,5 @@
Check [WILDCARD]/bench/no_run.ts
error: TS2322 [ERROR]: Type 'number' is not assignable to type 'string'.
const _value: string = 1;
~~~~~~
at [WILDCARD]/bench/no_run.ts:1:7

2
cli/tests/testdata/bench/no_run.ts vendored Normal file
View file

@ -0,0 +1,2 @@
const _value: string = 1;
console.log("this should not be run");

View file

@ -590,6 +590,10 @@ pub async fn run_benchmarks(
check_specifiers(&ps, permissions.clone(), specifiers.clone()).await?;
if bench_options.no_run {
return Ok(());
}
bench_specifiers(
&ps,
&permissions,
@ -742,6 +746,10 @@ pub async fn run_benchmarks_with_watch(
check_specifiers(&ps, permissions.clone(), specifiers.clone()).await?;
if bench_options.no_run {
return Ok(());
}
bench_specifiers(
&ps,
permissions,