Fix panic on --runs 0 (#923)

* fix: reject --runs/--max-runs 0, clamp --min-runs to 1

* Validate positive run counts with clap

---------

Co-authored-by: VXNCXNX <VXNCXNX@users.noreply.github.com>
Co-authored-by: David Peter <mail@david-peter.de>
This commit is contained in:
authored and GitHub committed 2026-10-02 09:56:27 +00:00
1 parent 8d908b0754
commit 907de26344
3 files changed
+37 -14

No files matched your search

+26
View File
@@ -74,6 +74,32 @@ fn exits_quietly_when_stdout_is_closed() {
}
}
#[test]
fn fails_with_zero_runs() {
for option in ["--runs", "--min-runs", "--max-runs"] {
hyperfine()
.arg(option)
.arg("0")
.arg("echo dummy benchmark")
.assert()
.code(2)
.stderr(predicate::str::contains(format!(
"invalid value '0' for '{option} <NUM>'"
)));
}
}
#[test]
fn min_runs_of_one_still_performs_one_run() {
hyperfine_debug()
.arg("--min-runs=1")
.arg("--warmup=0")
.arg("sleep 4")
.assert()
.success()
.stdout(predicate::str::contains("Time (abs ≡)"));
}
#[test]
fn can_run_commands_without_a_shell() {
hyperfine()