integration_tests.rs
This file
Path
tests/integration_tests.rs
1,389 lines · 40.2 KiB · Rust
Last changed by
Add migration guidance for removed --reference optionDavid Peterbefore adoption26760e8
History of this fileTake it
The walk stopped after 200 commits: lines older than 0f91d0c point at it.
Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
line 1why, one step back1mod common;Handle broken pipe errors on stdout gracefully (#932)jkbefore adoptionc0b3834
line 2why, one step back2use common::{hyperfine, hyperfine_raw_command};Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
line 3why, one step back3Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 4–5why, one step back4use assert_cmd::assert::OutputAssertExt;5use insta_cmd::assert_cmd_snapshot;Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 6–7why, one step back6use predicates::prelude::*;7fix(tests): restrict 'cat' tests to unix environments. Fixes #776 (#777)Ritvikbefore adoption3bd38f2
lines 8–13why, one step back8/// Platform-specific I/O utility.9/// - On Unix-like systems, defaults to `cat`.10/// - On Windows, uses `findstr` as an alternative.11/// See: <https://superuser.com/questions/853580/real-windows-equivalent-to-cat-stdin>12const STDIN_READ_COMMAND: &str = if cfg!(windows) { "findstr x*" } else { "cat" };13Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 14–15why, one step back14pub fn hyperfine_debug() -> std::process::Command {15 let mut cmd = hyperfine_raw_command();Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 16–19why, one step back16 cmd.arg("--debug-mode");17 cmd18}19Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 20–26why, one step back20fn snapshot_settings() -> insta::Settings {21 let mut settings = insta::Settings::clone_current();22 // Ignore trailing report padding while preserving indentation and internal spacing.23 settings.add_filter(r"(?m)[ \t]+$", "");24 settings25}26Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
lines 27–37why, one step back27fn json_snapshot_settings() -> insta::Settings {28 let mut settings = snapshot_settings();29 for field in ["hyperfine_version", "start_time", "os", "architecture"] {30 settings.add_filter(31 &format!(r#"("{field}": ")[^"]+(")"#),32 format!(r#"${{1}}[{field}]$2"#),33 );34 }35 settings36}37Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 38–47why, one step back38#[test]39fn runs_successfully() {40 hyperfine()41 .arg("--runs=2")42 .arg("echo dummy benchmark")43 .assert()44 .success();45}4647#[test]Add migration guidance for removed --reference optionDavid Peterbefore adoption26760e8
lines 48–66why, one step back48fn rejects_removed_reference_option_with_migration_guidance() {49 for args in [50 vec!["--reference", "echo reference", "echo comparison"],51 vec!["echo comparison", "--reference=echo reference"],52 vec!["--reference", "echo reference"],53 vec!["--reference"],54 ] {55 hyperfine()56 .args(args)57 .assert()58 .code(2)59 .stdout("")60 .stderr(predicate::str::contains(61 "The --reference option has been removed. Put your reference command first instead.",62 ));63 }64}6566#[test]Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 67–72why, one step back67fn one_run_is_supported() {68 hyperfine()69 .arg("--runs=1")70 .arg("echo dummy benchmark")71 .assert()72 .success();Handle broken pipe errors on stdout gracefully (#932)jkbefore adoptionc0b3834
lines 73–74why, one step back73}74Add --env for benchmark environment overridesDavid Peterbefore adoption6dddb02
lines 75–134why, one step back75#[test]76fn environment_basic_usage() {77 let command = if cfg!(windows) {78 "echo %HYPERFINE_TEST%"79 } else {80 "echo \"$HYPERFINE_TEST\""81 };82 hyperfine()83 .args(["--shell=default", "--runs=1", "--show-output"])84 .arg("--command-name=env-test")85 .args(["--env", r#"HYPERFINE_TEST="hello, world""#])86 .arg(command)87 .assert()88 .success()89 .stdout(predicate::str::contains("hello, world"));90}9192#[test]93fn environment_parameter_expansion() {94 let command = if cfg!(windows) {95 "echo %HYPERFINE_TEST%"96 } else {97 "echo \"$HYPERFINE_TEST\""98 };99 hyperfine()100 .args(["--shell=default", "--runs=1", "--show-output"])101 .arg("--command-name=env-test")102 .args(["-P", "value", "1", "2"])103 .args(["--env", "HYPERFINE_TEST=hello-{value}"])104 .arg(command)105 .assert()106 .success()107 .stdout(predicate::str::contains("hello-1"))108 .stdout(predicate::str::contains("hello-2"));109}110111#[test]112fn rejects_invalid_environment() {113 hyperfine()114 .args(["--env", "OMP_NUM_THREADS"])115 .arg("my_command")116 .assert()117 .failure()118 .stderr(predicate::str::contains(119 "Invalid value 'OMP_NUM_THREADS' for '--env': expected an assignment like NAME=value or NAME=\"quoted value\".",120 ));121}122123#[test]124fn requires_explicit_shell_for_environment_assignments() {125 // Without an explicit shell choice, report the leading variable assignment.126 hyperfine()127 .args(["--runs=1", "SOME_ENV_VAR=$HOME my_command"])128 .assert()129 .failure()130 .stderr(predicate::str::contains(131 "starts with a variable assignment",132 ));133}134Handle broken pipe errors on stdout gracefully (#932)jkbefore adoptionc0b3834
lines 135–173why, one step back135/// Regression test: hyperfine must not panic when writing to a closed136/// stdout pipe (e.g. `hyperfine ... | head -n 1` or a downstream process137/// that terminates early). A `BrokenPipe` error should result in a quiet138/// exit with code 0 instead of a `println!` panic.139#[test]140fn exits_quietly_when_stdout_is_closed() {141 use std::process::Stdio;142143 for args in [144 vec!["--runs=1", "echo dummy benchmark"],145 vec!["--runs=1", "--export-json=-", "echo dummy benchmark"],146 vec!["--runs=1", "echo dummy benchmark", "echo second benchmark"],147 ] {148 // A pipe whose read end has been closed before hyperfine is even149 // started: every write to it will fail with `BrokenPipe`.150 let (reader, writer) = std::io::pipe().expect("failed to create pipe");151 drop(reader);152153 let output = hyperfine_raw_command()154 .args(&args)155 .stdout(writer)156 .stderr(Stdio::piped())157 .spawn()158 .expect("failed to spawn hyperfine")159 .wait_with_output()160 .expect("failed to wait for hyperfine");161 let stderr = String::from_utf8_lossy(&output.stderr);162163 assert!(164 !stderr.contains("panicked"),165 "hyperfine panicked while writing to a closed pipe:\n{}",166 stderr167 );168 assert!(169 output.status.success(),170 "hyperfine did not exit cleanly; stderr:\n{}",171 stderr172 );173 }Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 174–176why, one step back174}175176#[test]Fix panic on --runs 0 (#923)Vincentbefore adoption907de26
lines 177–192why, one step back177fn fails_with_zero_runs() {178 for option in ["--runs", "--min-runs", "--max-runs"] {179 hyperfine()180 .arg(option)181 .arg("0")182 .arg("echo dummy benchmark")183 .assert()184 .code(2)185 .stderr(predicate::str::contains(format!(186 "invalid value '0' for '{option} <NUM>'"187 )));188 }189}190191#[test]192fn min_runs_of_one_still_performs_one_run() {Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 193–196why, one step back193 let _settings = snapshot_settings().bind_to_scope();194 assert_cmd_snapshot!(hyperfine_debug()195 .arg("--style=basic")196 .arg("--metrics=time_wall_clock")Fix panic on --runs 0 (#923)Vincentbefore adoption907de26
lines 197–198why, one step back197 .arg("--min-runs=1")198 .arg("--warmup=0")Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 199–209why, one step back199 .arg("sleep 4"), @"200 success: true201 exit_code: 0202 ----- stdout -----203 Benchmark 1: sleep 4 (1 run)204 Value205 Wall Time 4.000 s206207208 ----- stderr -----209 ");Fix panic on --runs 0 (#923)Vincentbefore adoption907de26
lines 210–212why, one step back210}211212#[test]Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 213–247why, one step back213fn can_run_commands_without_a_shell() {214 hyperfine()215 .arg("--runs=1")216 .arg("--show-output")217 .arg("--shell=none")218 .arg("echo 'hello world' argument2")219 .assert()220 .success()221 .stdout(predicate::str::contains("hello world argument2"));222}223224#[test]225fn fails_with_wrong_number_of_command_name_arguments() {226 hyperfine()227 .arg("--command-name=a")228 .arg("--command-name=b")229 .arg("echo a")230 .assert()231 .failure()232 .stderr(predicate::str::contains("Too many --command-name options"));233}234235#[test]236fn fails_with_wrong_number_of_prepare_options() {237 hyperfine()238 .arg("--runs=1")239 .arg("--prepare=echo a")240 .arg("--prepare=echo b")241 .arg("echo a")242 .arg("echo b")243 .assert()244 .success();245246 hyperfine()247 .arg("--runs=1")Fix prepare and conclude behaviour and add tests.Jan-Eric Nitschkebefore adoptiond4749b0
line 248why, one step back248 .arg("--prepare=echo ref")Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 249–250why, one step back249 .arg("--prepare=echo a")250 .arg("--prepare=echo b")Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 251why, one step back251 .arg("echo ref")Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 252–253why, one step back252 .arg("echo a")253 .arg("echo b")Fix prepare and conclude behaviour and add tests.Jan-Eric Nitschkebefore adoptiond4749b0
lines 254–262why, one step back254 .assert()255 .success();256257 hyperfine()258 .arg("--runs=1")259 .arg("--prepare=echo a")260 .arg("--prepare=echo b")261 .arg("echo a")262 .arg("echo b")Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 263–268why, one step back263 .arg("echo c")264 .assert()265 .failure()266 .stderr(predicate::str::contains(267 "The '--prepare' option has to be provided",268 ));Fix prepare and conclude behaviour and add tests.Jan-Eric Nitschkebefore adoptiond4749b0
lines 269–273why, one step back269270 hyperfine()271 .arg("--runs=1")272 .arg("--prepare=echo a")273 .arg("--prepare=echo b")Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 274why, one step back274 .arg("echo ref")Fix prepare and conclude behaviour and add tests.Jan-Eric Nitschkebefore adoptiond4749b0
lines 275–281why, one step back275 .arg("echo a")276 .arg("echo b")277 .assert()278 .failure()279 .stderr(predicate::str::contains(280 "The '--prepare' option has to be provided",281 ));Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 282–284why, one step back282}283284#[test]Add --conclude option with testsJack O'Connorbefore adoptione13d0cb
lines 285–296why, one step back285fn fails_with_wrong_number_of_conclude_options() {286 hyperfine()287 .arg("--runs=1")288 .arg("--conclude=echo a")289 .arg("--conclude=echo b")290 .arg("echo a")291 .arg("echo b")292 .assert()293 .success();294295 hyperfine()296 .arg("--runs=1")Fix prepare and conclude behaviour and add tests.Jan-Eric Nitschkebefore adoptiond4749b0
line 297why, one step back297 .arg("--conclude=echo ref")Add --conclude option with testsJack O'Connorbefore adoptione13d0cb
lines 298–299why, one step back298 .arg("--conclude=echo a")299 .arg("--conclude=echo b")Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 300why, one step back300 .arg("echo ref")Add --conclude option with testsJack O'Connorbefore adoptione13d0cb
lines 301–302why, one step back301 .arg("echo a")302 .arg("echo b")Fix prepare and conclude behaviour and add tests.Jan-Eric Nitschkebefore adoptiond4749b0
lines 303–311why, one step back303 .assert()304 .success();305306 hyperfine()307 .arg("--runs=1")308 .arg("--conclude=echo a")309 .arg("--conclude=echo b")310 .arg("echo a")311 .arg("echo b")Add --conclude option with testsJack O'Connorbefore adoptione13d0cb
lines 312–317why, one step back312 .arg("echo c")313 .assert()314 .failure()315 .stderr(predicate::str::contains(316 "The '--conclude' option has to be provided",317 ));Fix prepare and conclude behaviour and add tests.Jan-Eric Nitschkebefore adoptiond4749b0
lines 318–322why, one step back318319 hyperfine()320 .arg("--runs=1")321 .arg("--conclude=echo a")322 .arg("--conclude=echo b")Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 323why, one step back323 .arg("echo ref")Fix prepare and conclude behaviour and add tests.Jan-Eric Nitschkebefore adoptiond4749b0
lines 324–330why, one step back324 .arg("echo a")325 .arg("echo b")326 .assert()327 .failure()328 .stderr(predicate::str::contains(329 "The '--conclude' option has to be provided",330 ));Add --conclude option with testsJack O'Connorbefore adoptione13d0cb
lines 331–333why, one step back331}332333#[test]Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 334–348why, one step back334fn fails_with_duplicate_parameter_names() {335 hyperfine()336 .arg("--parameter-list")337 .arg("x")338 .arg("1,2,3")339 .arg("--parameter-list")340 .arg("x")341 .arg("a,b,c")342 .arg("echo test")343 .assert()344 .failure()345 .stderr(predicate::str::contains("Duplicate parameter names: x"));346}347348#[test]Require an explicit shell choice for shell operatorsDavid Peterbefore adoption6cb7bb0
lines 349–384why, one step back349fn requires_explicit_shell_for_shell_syntax() {350 let directory = tempfile::tempdir().unwrap();351352 let assert = hyperfine()353 .current_dir(directory.path())354 .arg("rm -rf cache/ && ./my_command")355 .assert()356 .failure();357358 insta::assert_snapshot!(String::from_utf8_lossy(&assert.get_output().stderr), @"359 Error: Command 'rm -rf cache/ && ./my_command' contains unquoted shell syntax ('&&').360 Explicitly choose how to execute it:361 -S / --shell=default Interpret shell syntax.362 -N / --shell=none Run directly, passing '&&' as a literal argument.363 ");364365 hyperfine()366 .arg("--show-output")367 .arg("--command-name=benchmark")368 .args(["--shell=default", "--runs=1", "echo before && echo after"])369 .assert()370 .success()371 .stdout(predicate::str::contains("before"))372 .stdout(predicate::str::contains("after"))373 .stdout(predicate::str::contains("&&").not());374375 hyperfine()376 .arg("--show-output")377 .arg("--command-name=benchmark")378 .args(["--shell=none", "--runs=1", "echo before && echo after"])379 .assert()380 .success()381 .stdout(predicate::str::contains("before && echo after"));382}383384#[test]Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 385–386why, one step back385fn fails_for_unknown_command() {386 hyperfine()Make --shell=none the default (#982)David Peterbefore adoptionab86cb9
line 387why, one step back387 .arg("--shell=default")Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 388–392why, one step back388 .arg("--runs=1")389 .arg("some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577")390 .assert()391 .failure()392 .stderr(predicate::str::contains(Run setup/cleanup commands in a shell (#990)David Peterbefore adoption4a9e066
line 393why, one step back393 "Command 'some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577' terminated with non-zero exit code",Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 394–415why, one step back394 ));395}396397#[test]398fn fails_for_unknown_command_without_shell() {399 hyperfine()400 .arg("--shell=none")401 .arg("--runs=1")402 .arg("some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577")403 .assert()404 .failure()405 .stderr(predicate::str::contains(406 "Failed to run command 'some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577'",407 ));408}409410#[cfg(unix)]411#[test]412fn fails_for_failing_command_without_shell() {413 hyperfine()414 .arg("--shell=none")415 .arg("--runs=1")Run setup/cleanup commands in a shell (#990)David Peterbefore adoption4a9e066
lines 416–418why, one step back416 .arg("--command-name=named benchmark")417 .args(["--parameter-list", "status", "0,1"])418 .arg("test {status} -eq 0")Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 419–421why, one step back419 .assert()420 .failure()421 .stderr(predicate::str::contains(Run setup/cleanup commands in a shell (#990)David Peterbefore adoption4a9e066
lines 422–424why, one step back422 "Command 'test 1 -eq 0' terminated with non-zero exit code 1 in the first benchmark run.",423 ))424 .stderr(predicate::str::contains("--ignore-failure"));Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 425–429why, one step back425}426427#[test]428fn fails_for_unknown_setup_command() {429 hyperfine()Make --shell=none the default (#982)David Peterbefore adoptionab86cb9
line 430why, one step back430 .arg("--shell=default")Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 431–435why, one step back431 .arg("--runs=1")432 .arg("--setup=some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577")433 .arg("echo test")434 .assert()435 .failure()Run setup/cleanup commands in a shell (#990)David Peterbefore adoption4a9e066
line 436why, one step back436 .stderr(predicate::str::contains("The setup command failed:"));Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 437–441why, one step back437}438439#[test]440fn fails_for_unknown_cleanup_command() {441 hyperfine()Make --shell=none the default (#982)David Peterbefore adoptionab86cb9
line 442why, one step back442 .arg("--shell=default")Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 443–447why, one step back443 .arg("--runs=1")444 .arg("--cleanup=some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577")445 .arg("echo test")446 .assert()447 .failure()Run setup/cleanup commands in a shell (#990)David Peterbefore adoption4a9e066
line 448why, one step back448 .stderr(predicate::str::contains("The cleanup command failed:"));Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 449–453why, one step back449}450451#[test]452fn fails_for_unknown_prepare_command() {453 hyperfine()Make --shell=none the default (#982)David Peterbefore adoptionab86cb9
line 454why, one step back454 .arg("--shell=default")Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 455–458why, one step back455 .arg("--prepare=some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577")456 .arg("echo test")457 .assert()458 .failure()Run setup/cleanup commands in a shell (#990)David Peterbefore adoption4a9e066
line 459why, one step back459 .stderr(predicate::str::contains("The preparation command failed:"));Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 460–461why, one step back460}461Add --conclude option with testsJack O'Connorbefore adoptione13d0cb
lines 462–464why, one step back462#[test]463fn fails_for_unknown_conclude_command() {464 hyperfine()Make --shell=none the default (#982)David Peterbefore adoptionab86cb9
line 465why, one step back465 .arg("--shell=default")Add --conclude option with testsJack O'Connorbefore adoptione13d0cb
lines 466–469why, one step back466 .arg("--conclude=some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577")467 .arg("echo test")468 .assert()469 .failure()Run setup/cleanup commands in a shell (#990)David Peterbefore adoption4a9e066
line 470why, one step back470 .stderr(predicate::str::contains("The conclusion command failed:"));Add --conclude option with testsJack O'Connorbefore adoptione13d0cb
lines 471–472why, one step back471}472Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 473–480why, one step back473#[cfg(unix)]474#[test]475fn can_run_failing_commands_with_ignore_failure_option() {476 hyperfine()477 .arg("false")478 .assert()479 .failure()480 .stderr(predicate::str::contains(Run setup/cleanup commands in a shell (#990)David Peterbefore adoption4a9e066
line 481why, one step back481 "Command 'false' terminated with non-zero exit code",Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 482–491why, one step back482 ));483484 hyperfine()485 .arg("--runs=1")486 .arg("--ignore-failure")487 .arg("false")488 .assert()489 .success();490}491Support list of exit codes in --ignore-failureDavid Peterbefore adoptionb5a6860
lines 492–496why, one step back492#[cfg(unix)]493#[test]494fn can_ignore_specific_exit_codes() {495 // Test that specifying exit code 1 ignores it496 hyperfine()Make --shell=none the default (#982)David Peterbefore adoptionab86cb9
line 497why, one step back497 .arg("--shell=default")Support list of exit codes in --ignore-failureDavid Peterbefore adoptionb5a6860
lines 498–505why, one step back498 .arg("--runs=1")499 .arg("--ignore-failure=1")500 .arg("exit 1")501 .assert()502 .success();503504 // Test that other exit codes still fail505 hyperfine()Make --shell=none the default (#982)David Peterbefore adoptionab86cb9
line 506why, one step back506 .arg("--shell=default")Support list of exit codes in --ignore-failureDavid Peterbefore adoptionb5a6860
lines 507–512why, one step back507 .arg("--runs=1")508 .arg("--ignore-failure=1")509 .arg("exit 2")510 .assert()511 .failure()512 .stderr(predicate::str::contains(Run setup/cleanup commands in a shell (#990)David Peterbefore adoption4a9e066
line 513why, one step back513 "Command 'exit 2' terminated with non-zero exit code 2",Support list of exit codes in --ignore-failureDavid Peterbefore adoptionb5a6860
lines 514–521why, one step back514 ));515}516517#[cfg(unix)]518#[test]519fn can_ignore_multiple_exit_codes() {520 // Test that all specified exit codes are ignored521 hyperfine()Make --shell=none the default (#982)David Peterbefore adoptionab86cb9
line 522why, one step back522 .arg("--shell=default")Support list of exit codes in --ignore-failureDavid Peterbefore adoptionb5a6860
lines 523–529why, one step back523 .arg("--runs=1")524 .arg("--ignore-failure=1,2,3")525 .arg("exit 1")526 .assert()527 .success();528529 hyperfine()Make --shell=none the default (#982)David Peterbefore adoptionab86cb9
line 530why, one step back530 .arg("--shell=default")Support list of exit codes in --ignore-failureDavid Peterbefore adoptionb5a6860
lines 531–537why, one step back531 .arg("--runs=1")532 .arg("--ignore-failure=1,2,3")533 .arg("exit 2")534 .assert()535 .success();536537 hyperfine()Make --shell=none the default (#982)David Peterbefore adoptionab86cb9
line 538why, one step back538 .arg("--shell=default")Support list of exit codes in --ignore-failureDavid Peterbefore adoptionb5a6860
lines 539–546why, one step back539 .arg("--runs=1")540 .arg("--ignore-failure=1,2,3")541 .arg("exit 3")542 .assert()543 .success();544545 // Test that other exit codes still fail546 hyperfine()Make --shell=none the default (#982)David Peterbefore adoptionab86cb9
line 547why, one step back547 .arg("--shell=default")Support list of exit codes in --ignore-failureDavid Peterbefore adoptionb5a6860
lines 548–553why, one step back548 .arg("--runs=1")549 .arg("--ignore-failure=1,2,3")550 .arg("exit 4")551 .assert()552 .failure()553 .stderr(predicate::str::contains(Run setup/cleanup commands in a shell (#990)David Peterbefore adoption4a9e066
line 554why, one step back554 "Command 'exit 4' terminated with non-zero exit code 4",Support list of exit codes in --ignore-failureDavid Peterbefore adoptionb5a6860
lines 555–562why, one step back555 ));556}557558#[cfg(unix)]559#[test]560fn ignore_failure_with_all_non_zero() {561 // Test explicit "all-non-zero" mode562 hyperfine()Make --shell=none the default (#982)David Peterbefore adoptionab86cb9
line 563why, one step back563 .arg("--shell=default")Support list of exit codes in --ignore-failureDavid Peterbefore adoptionb5a6860
lines 564–570why, one step back564 .arg("--runs=1")565 .arg("--ignore-failure=all-non-zero")566 .arg("exit 5")567 .assert()568 .success();569}570Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 571–589why, one step back571#[test]572fn shows_output_of_benchmarked_command() {573 hyperfine()574 .arg("--runs=2")575 .arg("--command-name=dummy")576 .arg("--show-output")577 .arg("echo 4fd47015")578 .assert()579 .success()580 .stdout(predicate::str::contains("4fd47015").count(2));581}582583#[test]584fn runs_commands_using_user_defined_shell() {585 hyperfine()586 .arg("--runs=1")587 .arg("--show-output")588 .arg("--shell")589 .arg("echo 'custom_shell' '--shell-arg'")Run setup/cleanup commands in a shell (#990)David Peterbefore adoption4a9e066
lines 590–593why, one step back590 .arg("--setup=echo setup")591 .arg("--prepare=echo prepare")592 .arg("--conclude=echo conclude")593 .arg("--cleanup=echo cleanup")Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 594–596why, one step back594 .arg("echo benchmark")595 .assert()596 .success()Run setup/cleanup commands in a shell (#990)David Peterbefore adoption4a9e066
line 597why, one step back597 .stdout(predicate::str::contains("custom_shell --shell-arg").count(5))Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 598–610why, one step back598 .stdout(599 predicate::str::contains("custom_shell --shell-arg -c echo benchmark").or(600 predicate::str::contains("custom_shell --shell-arg /C echo benchmark"),601 ),602 );603}604605#[test]606fn can_pass_input_to_command_from_a_file() {607 hyperfine()608 .arg("--runs=1")609 .arg("--input=example_input_file.txt")610 .arg("--show-output")fix(tests): restrict 'cat' tests to unix environments. Fixes #776 (#777)Ritvikbefore adoption3bd38f2
line 611why, one step back611 .arg(STDIN_READ_COMMAND)Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 612–622why, one step back612 .assert()613 .success()614 .stdout(predicate::str::contains("This text is part of a file"));615}616617#[test]618fn fails_if_invalid_stdin_data_file_provided() {619 hyperfine()620 .arg("--runs=1")621 .arg("--input=example_non_existent_file.txt")622 .arg("--show-output")fix(tests): restrict 'cat' tests to unix environments. Fixes #776 (#777)Ritvikbefore adoption3bd38f2
line 623why, one step back623 .arg(STDIN_READ_COMMAND)Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 624–636why, one step back624 .assert()625 .failure()626 .stderr(predicate::str::contains(627 "The file 'example_non_existent_file.txt' specified as '--input' does not exist",628 ));629}630631#[test]632fn returns_mean_time_in_correct_unit() {633 hyperfine_debug()634 .arg("sleep 1.234")635 .assert()636 .success()Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 637why, one step back637 .stdout(predicate::str::is_match(r"Wall Time\s+1\.234 s\s+±").unwrap());Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 638–642why, one step back638639 hyperfine_debug()640 .arg("sleep 0.123")641 .assert()642 .success()Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 643why, one step back643 .stdout(predicate::str::is_match(r"Wall Time\s+123\.0 ms\s+±").unwrap());Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 644–645why, one step back644645 hyperfine_debug()Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 646why, one step back646 .arg("--metrics=time_wall_clock:ms")Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 647–649why, one step back647 .arg("sleep 1.234")648 .assert()649 .success()Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 650why, one step back650 .stdout(predicate::str::is_match(r"Wall Time\s+1234\.0 ms\s+±").unwrap());Add support for microseconds, closes #684David Peterbefore adoption4564977
lines 651–652why, one step back651652 hyperfine_debug()Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 653why, one step back653 .arg("--metrics=time_wall_clock:us")Add support for microseconds, closes #684David Peterbefore adoption4564977
lines 654–656why, one step back654 .arg("sleep 1.234")655 .assert()656 .success()Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 657why, one step back657 .stdout(predicate::str::is_match(r"Wall Time\s+1234000\.0 µs\s+±").unwrap());Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 658–701why, one step back658}659660#[test]661fn performs_ten_runs_for_slow_commands() {662 hyperfine_debug()663 .arg("sleep 0.5")664 .assert()665 .success()666 .stdout(predicate::str::contains("10 runs"));667}668669#[test]670fn performs_three_seconds_of_benchmarking_for_fast_commands() {671 hyperfine_debug()672 .arg("sleep 0.01")673 .assert()674 .success()675 .stdout(predicate::str::contains("300 runs"));676}677678#[test]679fn takes_shell_spawning_time_into_account_for_computing_number_of_runs() {680 hyperfine_debug()681 .arg("--shell=sleep 0.02")682 .arg("sleep 0.01")683 .assert()684 .success()685 .stdout(predicate::str::contains("100 runs"));686}687688#[test]689fn takes_preparation_command_into_account_for_computing_number_of_runs() {690 hyperfine_debug()691 .arg("--prepare=sleep 0.02")692 .arg("sleep 0.01")693 .assert()694 .success()695 .stdout(predicate::str::contains("100 runs"));696697 // Shell overhead needs to be added to both the prepare command and the actual command,698 // leading to a total benchmark time of (prepare + shell + cmd + shell = 0.1 s)699 hyperfine_debug()700 .arg("--shell=sleep 0.01")701 .arg("--prepare=sleep 0.03")Add --conclude option with testsJack O'Connorbefore adoptione13d0cb
lines 702–743why, one step back702 .arg("sleep 0.05")703 .assert()704 .success()705 .stdout(predicate::str::contains("30 runs"));706}707708#[test]709fn takes_conclusion_command_into_account_for_computing_number_of_runs() {710 hyperfine_debug()711 .arg("--conclude=sleep 0.02")712 .arg("sleep 0.01")713 .assert()714 .success()715 .stdout(predicate::str::contains("100 runs"));716717 // Shell overhead needs to be added to both the conclude command and the actual command,718 // leading to a total benchmark time of (cmd + shell + conclude + shell = 0.1 s)719 hyperfine_debug()720 .arg("--shell=sleep 0.01")721 .arg("--conclude=sleep 0.03")722 .arg("sleep 0.05")723 .assert()724 .success()725 .stdout(predicate::str::contains("30 runs"));726}727728#[test]729fn takes_both_preparation_and_conclusion_command_into_account_for_computing_number_of_runs() {730 hyperfine_debug()731 .arg("--prepare=sleep 0.01")732 .arg("--conclude=sleep 0.01")733 .arg("sleep 0.01")734 .assert()735 .success()736 .stdout(predicate::str::contains("100 runs"));737738 // Shell overhead needs to be added to both the prepare, conclude and the actual command,739 // leading to a total benchmark time of (prepare + shell + cmd + shell + conclude + shell = 0.1 s)740 hyperfine_debug()741 .arg("--shell=sleep 0.01")742 .arg("--prepare=sleep 0.01")743 .arg("--conclude=sleep 0.01")Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 744–750why, one step back744 .arg("sleep 0.05")745 .assert()746 .success()747 .stdout(predicate::str::contains("30 runs"));748}749750#[test]Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 751–773why, one step back751fn secondary_metrics_include_factors_for_large_changes() {752 // Mock CPU time is zero; secondary wall time still gets ratio annotations.753 let output = hyperfine_debug()754 .args([755 "--metrics=time_cpu,time_wall_clock",756 "--style=basic",757 "--runs=2",758 "sleep 1",759 "sleep 10",760 "sleep 0.1",761 ])762 .output()763 .unwrap();764 assert!(output.status.success(), "{:?}", output);765 let stdout = String::from_utf8(output.stdout).unwrap();766 assert!(stdout.contains("+900.0%"), "{}", stdout);767 assert!(stdout.contains("-90.0%"), "{}", stdout);768 assert!(stdout.contains("+900.0% (10.0x slower)"), "{}", stdout);769 assert!(stdout.contains("-90.0% (10.0x faster)"), "{}", stdout);770}771772#[test]773fn shows_multiple_metrics_relative_to_first_command() {Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 774–776why, one step back774 let _settings = snapshot_settings().bind_to_scope();775 assert_cmd_snapshot!(hyperfine_debug()776 .arg("--style=basic")Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 777–780why, one step back777 .arg("--metrics=time_wall_clock:ms,time_user:us,memory_peak_resident:MiB")778 .arg("sleep 0.0817")779 .arg("sleep 0.6155")780 .arg("sleep 0.1707"), @"Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 781–783why, one step back781 success: true782 exit_code: 0783 ----- stdout -----Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 784–788why, one step back784 Benchmark 1: sleep 0.0817 (36 runs)785 mean ± σ min … max786 Wall Time 81.7 ms ± 0.0 ms 81.7 ms … 81.7 ms787 User time 0.0 µs ± 0.0 µs 0.0 µs … 0.0 µs788 Memory 0.0 MiB ± 0.0 MiB 0.0 MiB … 0.0 MiBMerge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
line 789why, one step back789Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 790–794why, one step back790 Benchmark 2: sleep 0.6155 (10 runs)791 mean ± σ min … max792 Wall Time 615.5 ms ± 0.0 ms 615.5 ms … 615.5 ms +653.4% (7.5x slower)793 User time 0.0 µs ± 0.0 µs 0.0 µs … 0.0 µs N/A794 Memory 0.0 MiB ± 0.0 MiB 0.0 MiB … 0.0 MiB N/AMerge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
line 795why, one step back795Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 796–800why, one step back796 Benchmark 3: sleep 0.1707 (17 runs)797 mean ± σ min … max798 Wall Time 170.7 ms ± 0.0 ms 170.7 ms … 170.7 ms +108.9% (2.1x slower)799 User time 0.0 µs ± 0.0 µs 0.0 µs … 0.0 µs N/A800 Memory 0.0 MiB ± 0.0 MiB 0.0 MiB … 0.0 MiB N/AMerge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 801–804why, one step back801802803 ----- stderr -----804 ");Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 805–807why, one step back805}806807#[test]Change message for identical time and add test for itJan-Eric Nitschkebefore adoption13547e9
line 808why, one step back808fn shows_benchmark_comparison_with_same_time() {Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 809–810why, one step back809 let _settings = snapshot_settings().bind_to_scope();810 assert_cmd_snapshot!(hyperfine_debug()Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 811why, one step back811 .arg("--metrics=time_wall_clock,memory_peak_resident")Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
line 812why, one step back812 .arg("--style=basic")Change message for identical time and add test for itJan-Eric Nitschkebefore adoption13547e9
lines 813–817why, one step back813 .arg("--command-name=A")814 .arg("--command-name=B")815 .arg("sleep 1.0")816 .arg("sleep 1.0")817 .arg("sleep 2.0")Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 818why, one step back818 .arg("sleep 1000.0"), @"Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 819–821why, one step back819 success: true820 exit_code: 0821 ----- stdout -----Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 822–825why, one step back822 Benchmark 1: A (10 runs)823 mean ± σ min … max824 Wall Time 1.000 s ± 0.000 s 1.000 s … 1.000 s825 Memory 0.0 B ± 0.0 B 0.0 B … 0.0 BMerge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
line 826why, one step back826Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 827–830why, one step back827 Benchmark 2: B (10 runs)828 mean ± σ min … max829 Wall Time 1.000 s ± 0.000 s 1.000 s … 1.000 s 0.0%830 Memory 0.0 B ± 0.0 B 0.0 B … 0.0 B N/AMerge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
line 831why, one step back831Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 832–835why, one step back832 Benchmark 3: sleep 2.0 (10 runs)833 mean ± σ min … max834 Wall Time 2.000 s ± 0.000 s 2.000 s … 2.000 s +100.0% (2.0x slower)835 Memory 0.0 B ± 0.0 B 0.0 B … 0.0 B N/AMerge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
line 836why, one step back836Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 837–840why, one step back837 Benchmark 4: sleep 1000.0 (10 runs)838 mean ± σ min … max839 Wall Time 1000.000 s ± 0.000 s 1000.000 s … 1000.000 s +99900.0% (1000.0x slower)840 Memory 0.0 B ± 0.0 B 0.0 B … 0.0 B N/AMerge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 841–844why, one step back841842843 ----- stderr -----844 ");Change message for identical time and add test for itJan-Eric Nitschkebefore adoption13547e9
lines 845–847why, one step back845}846847#[test]Fix prepare and conclude behaviour and add tests.Jan-Eric Nitschkebefore adoptiond4749b0
line 848why, one step back848fn shows_benchmark_comparison_relative_to_reference() {Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 849–850why, one step back849 let _settings = snapshot_settings().bind_to_scope();850 assert_cmd_snapshot!(hyperfine_debug()Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 851why, one step back851 .arg("--metrics=time_wall_clock,memory_peak_resident")Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
line 852why, one step back852 .arg("--style=basic")Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 853why, one step back853 .arg("sleep 2.0")Fix prepare and conclude behaviour and add tests.Jan-Eric Nitschkebefore adoptiond4749b0
line 854why, one step back854 .arg("sleep 1.0")Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 855why, one step back855 .arg("sleep 3.0"), @"Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 856–858why, one step back856 success: true857 exit_code: 0858 ----- stdout -----Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 859–862why, one step back859 Benchmark 1: sleep 2.0 (10 runs)860 mean ± σ min … max861 Wall Time 2.000 s ± 0.000 s 2.000 s … 2.000 s862 Memory 0.0 B ± 0.0 B 0.0 B … 0.0 BMerge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
line 863why, one step back863Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 864–867why, one step back864 Benchmark 2: sleep 1.0 (10 runs)865 mean ± σ min … max866 Wall Time 1.000 s ± 0.000 s 1.000 s … 1.000 s -50.0% (2.0x faster)867 Memory 0.0 B ± 0.0 B 0.0 B … 0.0 B N/AMerge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
line 868why, one step back868Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 869–872why, one step back869 Benchmark 3: sleep 3.0 (10 runs)870 mean ± σ min … max871 Wall Time 3.000 s ± 0.000 s 3.000 s … 3.000 s +50.0% (1.5x slower)872 Memory 0.0 B ± 0.0 B 0.0 B … 0.0 B N/AMerge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 873–876why, one step back873874875 ----- stderr -----876 ");Fix prepare and conclude behaviour and add tests.Jan-Eric Nitschkebefore adoptiond4749b0
lines 877–879why, one step back877}878879#[test]Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 880why, one step back880fn comparison_and_markup_identify_first_command_as_reference() {Merge pull request #979 from sharkdp/fix/parameterized-referenceDavid Peterbefore adoption46e1f9f
lines 881–887why, one step back881 let _settings = snapshot_settings().bind_to_scope();882 let directory = tempfile::tempdir().unwrap();883 let export_path = directory.path().join("results.md");884 let output = hyperfine_debug()885 .args([886 "--style=basic",887 "--runs=1",Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 888why, one step back888 "--command-name=baseline",Merge pull request #979 from sharkdp/fix/parameterized-referenceDavid Peterbefore adoption46e1f9f
lines 889–891why, one step back889 "--export-markdown",890 ])891 .arg(&export_path)Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 892why, one step back892 .args(["sleep 2", "sleep 1", "sleep 2", "sleep 3"])Merge pull request #979 from sharkdp/fix/parameterized-referenceDavid Peterbefore adoption46e1f9f
lines 893–896why, one step back893 .output()894 .unwrap();895 assert!(output.status.success(), "{:?}", output);896 let stdout = String::from_utf8(output.stdout).unwrap();Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 897–904why, one step back897 assert!(898 stdout.contains("Benchmark 1: baseline (1 run)"),899 "{}",900 stdout901 );902 assert!(stdout.contains("-50.0%"), "{}", stdout);903 assert!(stdout.contains("0.0%"), "{}", stdout);904 assert!(stdout.contains("+50.0%"), "{}", stdout);Merge pull request #979 from sharkdp/fix/parameterized-referenceDavid Peterbefore adoption46e1f9f
line 905why, one step back905 let markdown = std::fs::read_to_string(export_path).unwrap();Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 906–912why, one step back906 insta::assert_snapshot!(markdown, @"907 | Command | Mean Wall Time [s] | Change | Factor |908 |:---|---:|---:|:---|909 | `baseline` | 2.000 | | |910 | `sleep 1` | 1.000 | -50.0% | (2.0x faster) |911 | `sleep 2` | 2.000 | 0.0% | |912 | `sleep 3` | 3.000 | +50.0% | (1.5x slower) |Merge pull request #979 from sharkdp/fix/parameterized-referenceDavid Peterbefore adoption46e1f9f
lines 913–920why, one step back913 ");914915 // Equal zero times have no meaningful relative factor.916 let output = hyperfine_debug()917 .args([918 "--style=none",919 "--runs=1",920 "--export-markdown=-",Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 921why, one step back921 "--command-name=baseline",Merge pull request #979 from sharkdp/fix/parameterized-referenceDavid Peterbefore adoption46e1f9f
lines 922–932why, one step back922 "sleep 0",923 "sleep 0",924 ])925 .output()926 .unwrap();927 assert!(output.status.success(), "{:?}", output);928 let markdown = String::from_utf8(output.stdout).unwrap();929 let row = markdown930 .lines()931 .find(|line| line.contains("sleep 0"))932 .unwrap();Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 933why, one step back933 assert!(row.ends_with("| N/A | |"), "{}", row);Merge pull request #979 from sharkdp/fix/parameterized-referenceDavid Peterbefore adoption46e1f9f
lines 934–936why, one step back934}935936#[test]Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
line 937why, one step back937fn performs_all_benchmarks_in_parameter_scan() {Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 938–939why, one step back938 let _settings = snapshot_settings().bind_to_scope();939 assert_cmd_snapshot!(hyperfine_debug()Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 940why, one step back940 .arg("--metrics=time_wall_clock,memory_peak_resident")Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
line 941why, one step back941 .arg("--style=basic")Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 942–947why, one step back942 .arg("--parameter-scan")943 .arg("time")944 .arg("30")945 .arg("45")946 .arg("--parameter-step-size")947 .arg("5")Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 948why, one step back948 .arg("sleep {time}"), @"Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 949–951why, one step back949 success: true950 exit_code: 0951 ----- stdout -----Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 952–955why, one step back952 Benchmark 1: sleep 30 (10 runs)953 mean ± σ min … max954 Wall Time 30.000 s ± 0.000 s 30.000 s … 30.000 s955 Memory 0.0 B ± 0.0 B 0.0 B … 0.0 BMerge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
line 956why, one step back956Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 957–960why, one step back957 Benchmark 2: sleep 35 (10 runs)958 mean ± σ min … max959 Wall Time 35.000 s ± 0.000 s 35.000 s … 35.000 s +16.7%960 Memory 0.0 B ± 0.0 B 0.0 B … 0.0 B N/AMerge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
line 961why, one step back961Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 962–965why, one step back962 Benchmark 3: sleep 40 (10 runs)963 mean ± σ min … max964 Wall Time 40.000 s ± 0.000 s 40.000 s … 40.000 s +33.3% (1.3x slower)965 Memory 0.0 B ± 0.0 B 0.0 B … 0.0 B N/AMerge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
line 966why, one step back966Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 967–970why, one step back967 Benchmark 4: sleep 45 (10 runs)968 mean ± σ min … max969 Wall Time 45.000 s ± 0.000 s 45.000 s … 45.000 s +50.0% (1.5x slower)970 Memory 0.0 B ± 0.0 B 0.0 B … 0.0 B N/AMerge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 971–974why, one step back971972973 ----- stderr -----974 ");Fix prepare and conclude behaviour and add tests.Jan-Eric Nitschkebefore adoptiond4749b0
lines 975–977why, one step back975}976977#[test]Merge pull request #951 from Likio3000/codex/reject-negative-parameter-stepsDavid Peterbefore adoption862625f
lines 978–992why, one step back978fn rejects_negative_parameter_steps() {979 for step in ["-1", "-1.0"] {980 hyperfine()981 .args(["--parameter-scan", "n", "0", "1"])982 .arg(format!("--parameter-step-size={step}"))983 .arg("echo {n}")984 .assert()985 .code(1)986 .stdout(predicate::str::is_empty())987 .stderr(predicate::str::contains(988 "Parameter step size must be positive",989 ));990 }991}992Merge pull request #979 from sharkdp/fix/parameterized-referenceDavid Peterbefore adoption46e1f9f
line 993why, one step back993#[cfg(unix)]Merge pull request #951 from Likio3000/codex/reject-negative-parameter-stepsDavid Peterbefore adoption862625f
line 994why, one step back994#[test]Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 995why, one step back995fn preserves_input_order_with_parameterized_prepare() {Merge pull request #979 from sharkdp/fix/parameterized-referenceDavid Peterbefore adoption46e1f9f
lines 996–1022why, one step back996 let directory = tempfile::tempdir().unwrap();997 let csv_path = directory.path().join("results.csv");998 let json_path = directory.path().join("results.json");999 let output = hyperfine_raw_command()1000 .args([1001 "--style=basic",1002 "--shell=none",1003 "--runs=1",1004 "-L",1005 "delay",1006 "0.2,0.4,0.6",1007 "--prepare",1008 "sleep {delay}",1009 "--export-csv",1010 ])1011 .arg(&csv_path)1012 .arg("--export-json")1013 .arg(&json_path)1014 .arg("echo a")1015 .output()1016 .unwrap();1017 assert!(output.status.success(), "{:?}", output);1018 let stdout = String::from_utf8(output.stdout).unwrap();1019 assert_eq!(stdout.matches("Benchmark ").count(), 3);1020 for (number, delay) in ["0.2", "0.4", "0.6"].iter().enumerate() {1021 assert!(1022 stdout.contains(&format!(Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 1023why, one step back1023 "Benchmark {}: echo a (delay = {}) (1 run)",Merge pull request #979 from sharkdp/fix/parameterized-referenceDavid Peterbefore adoption46e1f9f
lines 1024–1030why, one step back1024 number + 1,1025 delay1026 )),1027 "{}",1028 stdout1029 );1030 }Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 1031–1040why, one step back1031 assert!(1032 !stdout1033 .split("Benchmark 2")1034 .next()1035 .unwrap()1036 .contains("Change"),1037 "{}",1038 stdout1039 );1040 assert!(!stdout.contains("Change vs #1"));Merge pull request #979 from sharkdp/fix/parameterized-referenceDavid Peterbefore adoption46e1f9f
lines 1041–1058why, one step back10411042 let mut csv = csv::Reader::from_path(csv_path).unwrap();1043 assert!(csv1044 .headers()1045 .unwrap()1046 .iter()1047 .any(|header| header == "parameter_delay"));1048 assert_eq!(1049 csv.records().collect::<Result<Vec<_>, _>>().unwrap().len(),1050 31051 );1052 let json: serde_json::Value =1053 serde_json::from_slice(&std::fs::read(json_path).unwrap()).unwrap();1054 let results = json["results"].as_array().unwrap();1055 assert_eq!(results.len(), 3);1056 assert_eq!(1057 results1058 .iter()Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
line 1059why, one step back1059 .map(|result| result["parameters"]["delay"]["value"].as_str().unwrap())Merge pull request #979 from sharkdp/fix/parameterized-referenceDavid Peterbefore adoption46e1f9f
lines 1060–1065why, one step back1060 .collect::<Vec<_>>(),1061 ["0.2", "0.4", "0.6"]1062 );1063}10641065#[test]Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 1066why, one step back1066fn rejects_invalid_metric_before_export_or_setup() {Merge pull request #979 from sharkdp/fix/parameterized-referenceDavid Peterbefore adoption46e1f9f
lines 1067–1072why, one step back1067 let directory = tempfile::tempdir().unwrap();1068 let export_path = directory.path().join("results.csv");1069 let marker_path = directory.path().join("setup-ran");1070 std::fs::write(&export_path, "previous contents").unwrap();10711072 hyperfine()Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 1073–1080why, one step back1073 .args([1074 "--metrics=memory_peak_resident:ms",1075 "-P",1076 "secs",1077 "2",1078 "3",1079 "--setup",1080 ])Merge pull request #979 from sharkdp/fix/parameterized-referenceDavid Peterbefore adoption46e1f9f
lines 1081–1088why, one step back1081 .arg(format!("echo touched > \"{}\"", marker_path.display()))1082 .arg("--export-csv")1083 .arg(&export_path)1084 .arg("sleep {secs}")1085 .assert()1086 .failure()1087 .stdout(predicate::str::is_empty())1088 .stderr(predicate::str::contains(Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 1089why, one step back1089 "Unit 'ms' is not valid for metric 'memory_peak_resident'",Merge pull request #979 from sharkdp/fix/parameterized-referenceDavid Peterbefore adoption46e1f9f
lines 1090–1099why, one step back1090 ));1091 assert_eq!(1092 std::fs::read_to_string(export_path).unwrap(),1093 "previous contents"1094 );1095 assert!(!marker_path.exists());1096}10971098#[cfg(unix)]1099#[test]Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 1100why, one step back1100fn intermediate_markdown_retains_completed_reference() {Merge pull request #979 from sharkdp/fix/parameterized-referenceDavid Peterbefore adoption46e1f9f
lines 1101–1127why, one step back1101 let directory = tempfile::tempdir().unwrap();1102 let export_path = directory.path().join("results.md");1103 hyperfine()1104 .args([1105 "--style=none",1106 "--shell=none",1107 "--runs=1",1108 "-L",1109 "delay",1110 "0.01,0.02,0.03",1111 "--prepare",1112 "true",1113 "--prepare",1114 "false",1115 "--prepare",1116 "true",1117 "--export-markdown",1118 ])1119 .arg(&export_path)1120 .arg("sleep {delay}")1121 .assert()1122 .failure();1123 let markdown = std::fs::read_to_string(export_path).unwrap();1124 let row = markdown1125 .lines()1126 .find(|line| line.contains("sleep 0.01"))1127 .unwrap();Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 1128why, one step back1128 assert!(row.ends_with("| | |"), "{}", row);Merge pull request #979 from sharkdp/fix/parameterized-referenceDavid Peterbefore adoption46e1f9f
lines 1129–1131why, one step back1129}11301131#[test]Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 1132why, one step back1132fn markdown_export_uses_first_parameterized_benchmark_as_reference() {Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 1133–1134why, one step back1133 let _settings = snapshot_settings().bind_to_scope();1134 assert_cmd_snapshot!(hyperfine_debug()Merge pull request #979 from sharkdp/fix/parameterized-referenceDavid Peterbefore adoption46e1f9f
lines 1135–1145why, one step back1135 .args([1136 "--style=none",1137 "--runs=1",1138 "--export-markdown=-",1139 "-P",1140 "x",1141 "1",1142 "3",1143 "--command-name",1144 "case-{x}",1145 "sleep {x}",Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 1146why, one step back1146 ]), @"Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 1147–1150why, one step back1147 success: true1148 exit_code: 01149 ----- stdout -----1150Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 1151–1155why, one step back1151 | Command | Mean Wall Time [s] | Change | Factor |1152 |:---|---:|---:|:---|1153 | `case-1` | 1.000 | | |1154 | `case-2` | 2.000 | +100.0% | (2.0x slower) |1155 | `case-3` | 3.000 | +200.0% | (3.0x slower) |Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 1156–1159why, one step back115611571158 ----- stderr -----1159 ");Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 1160–1163why, one step back1160}11611162#[test]1163fn intermediate_results_are_not_exported_to_stdout() {Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 1164–1165why, one step back1164 let _settings = snapshot_settings().bind_to_scope();1165 assert_cmd_snapshot!(hyperfine_debug()Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 1166–1169why, one step back1166 .arg("--style=none") // To only see the Markdown export on stdout1167 .arg("--export-markdown")1168 .arg("-")1169 .arg("sleep 1")Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 1170why, one step back1170 .arg("sleep 2"), @"Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 1171–1174why, one step back1171 success: true1172 exit_code: 01173 ----- stdout -----1174Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 1175–1178why, one step back1175 | Command | Mean Wall Time [s] | Change | Factor |1176 |:---|---:|---:|:---|1177 | `sleep 1` | 1.000 ± 0.000 | | |1178 | `sleep 2` | 2.000 ± 0.000 | +100.0% | (2.0x slower) |Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 1179–1182why, one step back117911801181 ----- stderr -----1182 ");Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 1183–1206why, one step back1183}11841185#[test]1186#[cfg(unix)]1187fn exports_intermediate_results_to_file() {1188 use tempfile::tempdir;11891190 let tempdir = tempdir().unwrap();1191 let export_path = tempdir.path().join("results.md");11921193 hyperfine()1194 .arg("--runs=1")1195 .arg("--export-markdown")1196 .arg(&export_path)1197 .arg("true")1198 .arg("false")1199 .assert()1200 .failure();12011202 let contents = std::fs::read_to_string(export_path).unwrap();1203 assert!(contents.contains("true"));1204}12051206#[test]Merge pull request #950 from Likio3000/codex/preserve-exports-on-invalid-optionsDavid Peterbefore adoptiond3d67fc
lines 1207–1249why, one step back1207fn invalid_command_options_preserve_export_files() {1208 use tempfile::tempdir;12091210 for (option, values) in [1211 ("--prepare", ["echo first", "echo second"]),1212 ("--conclude", ["echo first", "echo second"]),1213 ("--output", ["null", "pipe"]),1214 ] {1215 let directory = tempdir().unwrap();1216 let existing_export = directory.path().join("previous.json");1217 let new_export = directory.path().join("new.csv");1218 let previous_results =1219 b"{\"results\":[{\"command\":\"previous benchmark\",\"mean\":1.0}]}\n";1220 std::fs::write(&existing_export, previous_results).unwrap();12211222 hyperfine()1223 .arg("--runs=1")1224 .arg("--export-json")1225 .arg(&existing_export)1226 .arg("--export-csv")1227 .arg(&new_export)1228 .args([option, values[0], option, values[1]])1229 .arg("echo benchmark")1230 .assert()1231 .failure()1232 .stderr(predicate::str::contains(format!(1233 "The '{option}' option has to be provided just once or N times"1234 )));12351236 assert_eq!(1237 std::fs::read(&existing_export).unwrap(),1238 previous_results,1239 "{option} validation must preserve previous results"1240 );1241 assert!(1242 !new_export.exists(),1243 "{} validation must not create export files",1244 option1245 );1246 }1247}12481249#[test]Merge pull request #947 from Likio3000/codex/fix-markdown-backticksDavid Peterbefore adoption0a61e33
lines 1250–1260why, one step back1250fn markdown_export_preserves_backticks_and_pipes_in_command_names() {1251 let _settings = snapshot_settings().bind_to_scope();1252 assert_cmd_snapshot!(hyperfine_debug()1253 .arg("--style=none")1254 .arg("--export-markdown=-")1255 .arg("--command-name=echo `uname` | cat")1256 .arg("sleep 1"), @r"1257 success: true1258 exit_code: 01259 ----- stdout -----1260Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 1261–1263why, one step back1261 | Command | Mean Wall Time [s] | Change | Factor |1262 |:---|---:|---:|:---|1263 | `` echo `uname` \| cat `` | 1.000 ± 0.000 | | |Merge pull request #947 from Likio3000/codex/fix-markdown-backticksDavid Peterbefore adoption0a61e33
lines 1264–1270why, one step back126412651266 ----- stderr -----1267 ");1268}12691270#[test]Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 1271–1285why, one step back1271fn unused_parameters_are_shown_in_benchmark_name() {1272 hyperfine()1273 .arg("--runs=2")1274 .arg("--parameter-list")1275 .arg("branch")1276 .arg("master,feature")1277 .arg("echo test")1278 .assert()1279 .success()1280 .stdout(1281 predicate::str::contains("echo test (branch = master)")1282 .and(predicate::str::contains("echo test (branch = feature)")),1283 );1284}1285test: windows quote argPedro Witzelbefore adoption25331f8
lines 1286–1289why, one step back1286#[cfg(windows)]1287#[test]1288fn windows_quote_args() {1289 hyperfine()Make --shell=none the default (#982)David Peterbefore adoptionab86cb9
line 1290why, one step back1290 .arg("--shell=default")test: windows quote argPedro Witzelbefore adoption25331f8
lines 1291–1299why, one step back1291 .arg("more \"example_input_file.txt\"")1292 .assert()1293 .success();1294}12951296#[cfg(windows)]1297#[test]1298fn windows_quote_before_quote_args() {1299 hyperfine()Make --shell=none the default (#982)David Peterbefore adoptionab86cb9
line 1300why, one step back1300 .arg("--shell=default")test: windows quote argPedro Witzelbefore adoption25331f8
lines 1301–1304why, one step back1301 .arg("dir \"..\\src\\\" \"..\\tests\\\"")1302 .assert()1303 .success();1304}Merge pull request #807 from willcl-ark/expose-run-varDavid Peterbefore adoption30a2b61
lines 1305–1317why, one step back13051306#[test]1307fn hyperfine_iteration_env_var_in_prepare_and_conclude_commands() {1308 let tempdir = tempfile::tempdir().unwrap();1309 let output_path = tempdir.path().join("iteration output.txt");1310 let iteration = if cfg!(windows) {1311 "%HYPERFINE_ITERATION%"1312 } else {1313 "$HYPERFINE_ITERATION"1314 };1315 let command = |phase| format!(r#"echo {phase}:{iteration} >> "iteration output.txt""#);13161317 hyperfine()Make --shell=none the default (#982)David Peterbefore adoptionab86cb9
line 1318why, one step back1318 .arg("--shell=default")Merge pull request #807 from willcl-ark/expose-run-varDavid Peterbefore adoption30a2b61
lines 1319–1346why, one step back1319 .current_dir(tempdir.path())1320 .arg("--runs=2")1321 .arg("--warmup=1")1322 .arg("--prepare")1323 .arg(command("prepare"))1324 .arg(command("benchmark"))1325 .arg("--conclude")1326 .arg(command("conclude"))1327 .assert()1328 .success();13291330 let contents = std::fs::read_to_string(output_path).unwrap();1331 // cmd.exe's echo includes the space before the redirection operator.1332 let lines: Vec<&str> = contents.lines().map(str::trim_end).collect();1333 assert_eq!(1334 lines,1335 [1336 "prepare:warmup-0",1337 "benchmark:warmup-0",1338 "conclude:warmup-0",1339 "prepare:0",1340 "benchmark:0",1341 "conclude:0",1342 "prepare:1",1343 "benchmark:1",1344 "conclude:1",1345 ]1346 );Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
lines 1347–1356why, one step back1347}13481349#[test]1350fn json_export_basic() {1351 let _settings = json_snapshot_settings().bind_to_scope();1352 assert_cmd_snapshot!(hyperfine_debug().args([1353 "--style=none",1354 "--export-json=-",1355 "--runs=2",1356 "--warmup=1",Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 1357–1358why, one step back1357 "--command-name=one second",1358 "sleep 1",Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
lines 1359–1388why, one step back1359 "--command-name=sleep 2",1360 "sleep 2",1361 ]));1362}13631364#[test]1365fn json_export_single_run() {1366 // Make sure that the standard deviation is set to `null`1367 let _settings = json_snapshot_settings().bind_to_scope();1368 assert_cmd_snapshot!(hyperfine_debug().args([1369 "--style=none",1370 "--export-json=-",1371 "--runs=1",1372 "sleep 1",1373 ]));1374}13751376#[test]1377fn json_export_parameterized_with_reference() {1378 let _settings = json_snapshot_settings().bind_to_scope();1379 assert_cmd_snapshot!(hyperfine_debug().args([1380 "--style=none",1381 "--export-json=-",1382 "--runs=2",1383 "-L",1384 "duration",1385 "1,2",1386 "--command-name=sleep for {duration} seconds",1387 "sleep {duration}",1388 ]));Merge pull request #807 from willcl-ark/expose-run-varDavid Peterbefore adoption30a2b61
line 1389why, one step back1389}