Skip to content

Commit

Permalink
feat(bench): add --no-run flag (denoland#18433)
Browse files Browse the repository at this point in the history
  • Loading branch information
GJZwiers committed Mar 26, 2023
1 parent 701099b commit a29d88b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cli/args/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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,
});
}

Expand Down Expand Up @@ -6482,6 +6492,7 @@ mod tests {
"--unstable",
"--no-npm",
"--no-remote",
"--no-run",
"--filter",
"- foo",
"--location",
Expand All @@ -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![],
Expand Down Expand Up @@ -6526,6 +6538,7 @@ mod tests {
subcommand: DenoSubcommand::Bench(BenchFlags {
filter: None,
json: false,
no_run: false,
files: FileFlags {
include: vec![],
ignore: vec![],
Expand Down
2 changes: 2 additions & 0 deletions cli/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ pub struct BenchOptions {
pub files: FilesConfig,
pub filter: Option<String>,
pub json: bool,
pub no_run: bool,
}

impl BenchOptions {
Expand All @@ -134,6 +135,7 @@ impl BenchOptions {
),
filter: bench_flags.filter,
json: bench_flags.json,
no_run: bench_flags.no_run,
})
}
}
Expand Down
6 changes: 6 additions & 0 deletions cli/tests/integration/bench_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions cli/tests/testdata/bench/no_run.out
Original file line number Diff line number Diff line change
@@ -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 changes: 2 additions & 0 deletions cli/tests/testdata/bench/no_run.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const _value: string = 1;
console.log("this should not be run");
8 changes: 8 additions & 0 deletions cli/tools/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit a29d88b

Please sign in to comment.