integration_tests.rs
This file
Path
tests/integration_tests.rs
1,081 lines · 30.2 KiB · Rust
Last changed by
Merge pull request #807 from willcl-ark/expose-run-varDavid Peterbefore adoption30a2b61
History of this fileTake it
The walk stopped after 200 commits: lines older than 8f20aed point at it.
Fix pipeline!David Peterbefore adoption8f20aed
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};Fix pipeline!David Peterbefore adoption8f20aed
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;Fix pipeline!David Peterbefore adoption8f20aed
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();Fix pipeline!David Peterbefore adoption8f20aed
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}26Fix pipeline!David Peterbefore adoption8f20aed
lines 27–42why, one step back27#[test]28fn runs_successfully() {29 hyperfine()30 .arg("--runs=2")31 .arg("echo dummy benchmark")32 .assert()33 .success();34}3536#[test]37fn one_run_is_supported() {38 hyperfine()39 .arg("--runs=1")40 .arg("echo dummy benchmark")41 .assert()42 .success();Handle broken pipe errors on stdout gracefully (#932)jkbefore adoptionc0b3834
lines 43–83why, one step back43}4445/// Regression test: hyperfine must not panic when writing to a closed46/// stdout pipe (e.g. `hyperfine ... | head -n 1` or a downstream process47/// that terminates early). A `BrokenPipe` error should result in a quiet48/// exit with code 0 instead of a `println!` panic.49#[test]50fn exits_quietly_when_stdout_is_closed() {51 use std::process::Stdio;5253 for args in [54 vec!["--runs=1", "echo dummy benchmark"],55 vec!["--runs=1", "--export-json=-", "echo dummy benchmark"],56 vec!["--runs=1", "echo dummy benchmark", "echo second benchmark"],57 ] {58 // A pipe whose read end has been closed before hyperfine is even59 // started: every write to it will fail with `BrokenPipe`.60 let (reader, writer) = std::io::pipe().expect("failed to create pipe");61 drop(reader);6263 let output = hyperfine_raw_command()64 .args(&args)65 .stdout(writer)66 .stderr(Stdio::piped())67 .spawn()68 .expect("failed to spawn hyperfine")69 .wait_with_output()70 .expect("failed to wait for hyperfine");71 let stderr = String::from_utf8_lossy(&output.stderr);7273 assert!(74 !stderr.contains("panicked"),75 "hyperfine panicked while writing to a closed pipe:\n{}",76 stderr77 );78 assert!(79 output.status.success(),80 "hyperfine did not exit cleanly; stderr:\n{}",81 stderr82 );83 }Fix pipeline!David Peterbefore adoption8f20aed
lines 84–86why, one step back84}8586#[test]Fix panic on --runs 0 (#923)Vincentbefore adoption907de26
lines 87–112why, one step back87fn fails_with_zero_runs() {88 for option in ["--runs", "--min-runs", "--max-runs"] {89 hyperfine()90 .arg(option)91 .arg("0")92 .arg("echo dummy benchmark")93 .assert()94 .code(2)95 .stderr(predicate::str::contains(format!(96 "invalid value '0' for '{option} <NUM>'"97 )));98 }99}100101#[test]102fn min_runs_of_one_still_performs_one_run() {103 hyperfine_debug()104 .arg("--min-runs=1")105 .arg("--warmup=0")106 .arg("sleep 4")107 .assert()108 .success()109 .stdout(predicate::str::contains("Time (abs ≡)"));110}111112#[test]Fix pipeline!David Peterbefore adoption8f20aed
lines 113–147why, one step back113fn can_run_commands_without_a_shell() {114 hyperfine()115 .arg("--runs=1")116 .arg("--show-output")117 .arg("--shell=none")118 .arg("echo 'hello world' argument2")119 .assert()120 .success()121 .stdout(predicate::str::contains("hello world argument2"));122}123124#[test]125fn fails_with_wrong_number_of_command_name_arguments() {126 hyperfine()127 .arg("--command-name=a")128 .arg("--command-name=b")129 .arg("echo a")130 .assert()131 .failure()132 .stderr(predicate::str::contains("Too many --command-name options"));133}134135#[test]136fn fails_with_wrong_number_of_prepare_options() {137 hyperfine()138 .arg("--runs=1")139 .arg("--prepare=echo a")140 .arg("--prepare=echo b")141 .arg("echo a")142 .arg("echo b")143 .assert()144 .success();145146 hyperfine()147 .arg("--runs=1")Fix prepare and conclude behaviour and add tests.Jan-Eric Nitschkebefore adoptiond4749b0
line 148why, one step back148 .arg("--prepare=echo ref")Fix pipeline!David Peterbefore adoption8f20aed
lines 149–150why, one step back149 .arg("--prepare=echo a")150 .arg("--prepare=echo b")Fix prepare and conclude behaviour and add tests.Jan-Eric Nitschkebefore adoptiond4749b0
line 151why, one step back151 .arg("--reference=echo ref")Fix pipeline!David Peterbefore adoption8f20aed
lines 152–153why, one step back152 .arg("echo a")153 .arg("echo b")Fix prepare and conclude behaviour and add tests.Jan-Eric Nitschkebefore adoptiond4749b0
lines 154–162why, one step back154 .assert()155 .success();156157 hyperfine()158 .arg("--runs=1")159 .arg("--prepare=echo a")160 .arg("--prepare=echo b")161 .arg("echo a")162 .arg("echo b")Fix pipeline!David Peterbefore adoption8f20aed
lines 163–168why, one step back163 .arg("echo c")164 .assert()165 .failure()166 .stderr(predicate::str::contains(167 "The '--prepare' option has to be provided",168 ));Fix prepare and conclude behaviour and add tests.Jan-Eric Nitschkebefore adoptiond4749b0
lines 169–181why, one step back169170 hyperfine()171 .arg("--runs=1")172 .arg("--prepare=echo a")173 .arg("--prepare=echo b")174 .arg("--reference=echo ref")175 .arg("echo a")176 .arg("echo b")177 .assert()178 .failure()179 .stderr(predicate::str::contains(180 "The '--prepare' option has to be provided",181 ));Fix pipeline!David Peterbefore adoption8f20aed
lines 182–184why, one step back182}183184#[test]Add --conclude option with testsJack O'Connorbefore adoptione13d0cb
lines 185–196why, one step back185fn fails_with_wrong_number_of_conclude_options() {186 hyperfine()187 .arg("--runs=1")188 .arg("--conclude=echo a")189 .arg("--conclude=echo b")190 .arg("echo a")191 .arg("echo b")192 .assert()193 .success();194195 hyperfine()196 .arg("--runs=1")Fix prepare and conclude behaviour and add tests.Jan-Eric Nitschkebefore adoptiond4749b0
line 197why, one step back197 .arg("--conclude=echo ref")Add --conclude option with testsJack O'Connorbefore adoptione13d0cb
lines 198–199why, one step back198 .arg("--conclude=echo a")199 .arg("--conclude=echo b")Fix prepare and conclude behaviour and add tests.Jan-Eric Nitschkebefore adoptiond4749b0
line 200why, one step back200 .arg("--reference=echo ref")Add --conclude option with testsJack O'Connorbefore adoptione13d0cb
lines 201–202why, one step back201 .arg("echo a")202 .arg("echo b")Fix prepare and conclude behaviour and add tests.Jan-Eric Nitschkebefore adoptiond4749b0
lines 203–211why, one step back203 .assert()204 .success();205206 hyperfine()207 .arg("--runs=1")208 .arg("--conclude=echo a")209 .arg("--conclude=echo b")210 .arg("echo a")211 .arg("echo b")Add --conclude option with testsJack O'Connorbefore adoptione13d0cb
lines 212–217why, one step back212 .arg("echo c")213 .assert()214 .failure()215 .stderr(predicate::str::contains(216 "The '--conclude' option has to be provided",217 ));Fix prepare and conclude behaviour and add tests.Jan-Eric Nitschkebefore adoptiond4749b0
lines 218–230why, one step back218219 hyperfine()220 .arg("--runs=1")221 .arg("--conclude=echo a")222 .arg("--conclude=echo b")223 .arg("--reference=echo ref")224 .arg("echo a")225 .arg("echo b")226 .assert()227 .failure()228 .stderr(predicate::str::contains(229 "The '--conclude' option has to be provided",230 ));Add --conclude option with testsJack O'Connorbefore adoptione13d0cb
lines 231–233why, one step back231}232233#[test]Fix pipeline!David Peterbefore adoption8f20aed
lines 234–324why, one step back234fn fails_with_duplicate_parameter_names() {235 hyperfine()236 .arg("--parameter-list")237 .arg("x")238 .arg("1,2,3")239 .arg("--parameter-list")240 .arg("x")241 .arg("a,b,c")242 .arg("echo test")243 .assert()244 .failure()245 .stderr(predicate::str::contains("Duplicate parameter names: x"));246}247248#[test]249fn fails_for_unknown_command() {250 hyperfine()251 .arg("--runs=1")252 .arg("some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577")253 .assert()254 .failure()255 .stderr(predicate::str::contains(256 "Command terminated with non-zero exit code",257 ));258}259260#[test]261fn fails_for_unknown_command_without_shell() {262 hyperfine()263 .arg("--shell=none")264 .arg("--runs=1")265 .arg("some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577")266 .assert()267 .failure()268 .stderr(predicate::str::contains(269 "Failed to run command 'some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577'",270 ));271}272273#[cfg(unix)]274#[test]275fn fails_for_failing_command_without_shell() {276 hyperfine()277 .arg("--shell=none")278 .arg("--runs=1")279 .arg("false")280 .assert()281 .failure()282 .stderr(predicate::str::contains(283 "Command terminated with non-zero exit code",284 ));285}286287#[test]288fn fails_for_unknown_setup_command() {289 hyperfine()290 .arg("--runs=1")291 .arg("--setup=some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577")292 .arg("echo test")293 .assert()294 .failure()295 .stderr(predicate::str::contains(296 "The setup command terminated with a non-zero exit code.",297 ));298}299300#[test]301fn fails_for_unknown_cleanup_command() {302 hyperfine()303 .arg("--runs=1")304 .arg("--cleanup=some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577")305 .arg("echo test")306 .assert()307 .failure()308 .stderr(predicate::str::contains(309 "The cleanup command terminated with a non-zero exit code.",310 ));311}312313#[test]314fn fails_for_unknown_prepare_command() {315 hyperfine()316 .arg("--prepare=some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577")317 .arg("echo test")318 .assert()319 .failure()320 .stderr(predicate::str::contains(321 "The preparation command terminated with a non-zero exit code.",322 ));323}324Add --conclude option with testsJack O'Connorbefore adoptione13d0cb
lines 325–336why, one step back325#[test]326fn fails_for_unknown_conclude_command() {327 hyperfine()328 .arg("--conclude=some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577")329 .arg("echo test")330 .assert()331 .failure()332 .stderr(predicate::str::contains(333 "The conclusion command terminated with a non-zero exit code.",334 ));335}336Fix pipeline!David Peterbefore adoption8f20aed
lines 337–355why, one step back337#[cfg(unix)]338#[test]339fn can_run_failing_commands_with_ignore_failure_option() {340 hyperfine()341 .arg("false")342 .assert()343 .failure()344 .stderr(predicate::str::contains(345 "Command terminated with non-zero exit code",346 ));347348 hyperfine()349 .arg("--runs=1")350 .arg("--ignore-failure")351 .arg("false")352 .assert()353 .success();354}355Support list of exit codes in --ignore-failureDavid Peterbefore adoptionb5a6860
lines 356–427why, one step back356#[cfg(unix)]357#[test]358fn can_ignore_specific_exit_codes() {359 // Test that specifying exit code 1 ignores it360 hyperfine()361 .arg("--runs=1")362 .arg("--ignore-failure=1")363 .arg("exit 1")364 .assert()365 .success();366367 // Test that other exit codes still fail368 hyperfine()369 .arg("--runs=1")370 .arg("--ignore-failure=1")371 .arg("exit 2")372 .assert()373 .failure()374 .stderr(predicate::str::contains(375 "Command terminated with non-zero exit code 2",376 ));377}378379#[cfg(unix)]380#[test]381fn can_ignore_multiple_exit_codes() {382 // Test that all specified exit codes are ignored383 hyperfine()384 .arg("--runs=1")385 .arg("--ignore-failure=1,2,3")386 .arg("exit 1")387 .assert()388 .success();389390 hyperfine()391 .arg("--runs=1")392 .arg("--ignore-failure=1,2,3")393 .arg("exit 2")394 .assert()395 .success();396397 hyperfine()398 .arg("--runs=1")399 .arg("--ignore-failure=1,2,3")400 .arg("exit 3")401 .assert()402 .success();403404 // Test that other exit codes still fail405 hyperfine()406 .arg("--runs=1")407 .arg("--ignore-failure=1,2,3")408 .arg("exit 4")409 .assert()410 .failure()411 .stderr(predicate::str::contains(412 "Command terminated with non-zero exit code 4",413 ));414}415416#[cfg(unix)]417#[test]418fn ignore_failure_with_all_non_zero() {419 // Test explicit "all-non-zero" mode420 hyperfine()421 .arg("--runs=1")422 .arg("--ignore-failure=all-non-zero")423 .arg("exit 5")424 .assert()425 .success();426}427Fix pipeline!David Peterbefore adoption8f20aed
lines 428–462why, one step back428#[test]429fn shows_output_of_benchmarked_command() {430 hyperfine()431 .arg("--runs=2")432 .arg("--command-name=dummy")433 .arg("--show-output")434 .arg("echo 4fd47015")435 .assert()436 .success()437 .stdout(predicate::str::contains("4fd47015").count(2));438}439440#[test]441fn runs_commands_using_user_defined_shell() {442 hyperfine()443 .arg("--runs=1")444 .arg("--show-output")445 .arg("--shell")446 .arg("echo 'custom_shell' '--shell-arg'")447 .arg("echo benchmark")448 .assert()449 .success()450 .stdout(451 predicate::str::contains("custom_shell --shell-arg -c echo benchmark").or(452 predicate::str::contains("custom_shell --shell-arg /C echo benchmark"),453 ),454 );455}456457#[test]458fn can_pass_input_to_command_from_a_file() {459 hyperfine()460 .arg("--runs=1")461 .arg("--input=example_input_file.txt")462 .arg("--show-output")fix(tests): restrict 'cat' tests to unix environments. Fixes #776 (#777)Ritvikbefore adoption3bd38f2
line 463why, one step back463 .arg(STDIN_READ_COMMAND)Fix pipeline!David Peterbefore adoption8f20aed
lines 464–474why, one step back464 .assert()465 .success()466 .stdout(predicate::str::contains("This text is part of a file"));467}468469#[test]470fn fails_if_invalid_stdin_data_file_provided() {471 hyperfine()472 .arg("--runs=1")473 .arg("--input=example_non_existent_file.txt")474 .arg("--show-output")fix(tests): restrict 'cat' tests to unix environments. Fixes #776 (#777)Ritvikbefore adoption3bd38f2
line 475why, one step back475 .arg(STDIN_READ_COMMAND)Fix pipeline!David Peterbefore adoption8f20aed
lines 476–502why, one step back476 .assert()477 .failure()478 .stderr(predicate::str::contains(479 "The file 'example_non_existent_file.txt' specified as '--input' does not exist",480 ));481}482483#[test]484fn returns_mean_time_in_correct_unit() {485 hyperfine_debug()486 .arg("sleep 1.234")487 .assert()488 .success()489 .stdout(predicate::str::contains("Time (mean ± σ): 1.234 s ±"));490491 hyperfine_debug()492 .arg("sleep 0.123")493 .assert()494 .success()495 .stdout(predicate::str::contains("Time (mean ± σ): 123.0 ms ±"));496497 hyperfine_debug()498 .arg("--time-unit=millisecond")499 .arg("sleep 1.234")500 .assert()501 .success()502 .stdout(predicate::str::contains("Time (mean ± σ): 1234.0 ms ±"));Add support for microseconds, closes #684David Peterbefore adoption4564977
lines 503–511why, one step back503504 hyperfine_debug()505 .arg("--time-unit=microsecond")506 .arg("sleep 1.234")507 .assert()508 .success()509 .stdout(predicate::str::contains(510 "Time (mean ± σ): 1234000.0 µs ±",511 ));Fix pipeline!David Peterbefore adoption8f20aed
lines 512–555why, one step back512}513514#[test]515fn performs_ten_runs_for_slow_commands() {516 hyperfine_debug()517 .arg("sleep 0.5")518 .assert()519 .success()520 .stdout(predicate::str::contains("10 runs"));521}522523#[test]524fn performs_three_seconds_of_benchmarking_for_fast_commands() {525 hyperfine_debug()526 .arg("sleep 0.01")527 .assert()528 .success()529 .stdout(predicate::str::contains("300 runs"));530}531532#[test]533fn takes_shell_spawning_time_into_account_for_computing_number_of_runs() {534 hyperfine_debug()535 .arg("--shell=sleep 0.02")536 .arg("sleep 0.01")537 .assert()538 .success()539 .stdout(predicate::str::contains("100 runs"));540}541542#[test]543fn takes_preparation_command_into_account_for_computing_number_of_runs() {544 hyperfine_debug()545 .arg("--prepare=sleep 0.02")546 .arg("sleep 0.01")547 .assert()548 .success()549 .stdout(predicate::str::contains("100 runs"));550551 // Shell overhead needs to be added to both the prepare command and the actual command,552 // leading to a total benchmark time of (prepare + shell + cmd + shell = 0.1 s)553 hyperfine_debug()554 .arg("--shell=sleep 0.01")555 .arg("--prepare=sleep 0.03")Add --conclude option with testsJack O'Connorbefore adoptione13d0cb
lines 556–597why, one step back556 .arg("sleep 0.05")557 .assert()558 .success()559 .stdout(predicate::str::contains("30 runs"));560}561562#[test]563fn takes_conclusion_command_into_account_for_computing_number_of_runs() {564 hyperfine_debug()565 .arg("--conclude=sleep 0.02")566 .arg("sleep 0.01")567 .assert()568 .success()569 .stdout(predicate::str::contains("100 runs"));570571 // Shell overhead needs to be added to both the conclude command and the actual command,572 // leading to a total benchmark time of (cmd + shell + conclude + shell = 0.1 s)573 hyperfine_debug()574 .arg("--shell=sleep 0.01")575 .arg("--conclude=sleep 0.03")576 .arg("sleep 0.05")577 .assert()578 .success()579 .stdout(predicate::str::contains("30 runs"));580}581582#[test]583fn takes_both_preparation_and_conclusion_command_into_account_for_computing_number_of_runs() {584 hyperfine_debug()585 .arg("--prepare=sleep 0.01")586 .arg("--conclude=sleep 0.01")587 .arg("sleep 0.01")588 .assert()589 .success()590 .stdout(predicate::str::contains("100 runs"));591592 // Shell overhead needs to be added to both the prepare, conclude and the actual command,593 // leading to a total benchmark time of (prepare + shell + cmd + shell + conclude + shell = 0.1 s)594 hyperfine_debug()595 .arg("--shell=sleep 0.01")596 .arg("--prepare=sleep 0.01")597 .arg("--conclude=sleep 0.01")Fix pipeline!David Peterbefore adoption8f20aed
lines 598–605why, one step back598 .arg("sleep 0.05")599 .assert()600 .success()601 .stdout(predicate::str::contains("30 runs"));602}603604#[test]605fn shows_benchmark_comparison_with_relative_times() {Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 606–608why, one step back606 let _settings = snapshot_settings().bind_to_scope();607 assert_cmd_snapshot!(hyperfine_debug()608 .arg("--style=basic")Fix pipeline!David Peterbefore adoption8f20aed
lines 609–610why, one step back609 .arg("sleep 1.0")610 .arg("sleep 2.0")Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 611–633why, one step back611 .arg("sleep 3.0"), @r"612 success: true613 exit_code: 0614 ----- stdout -----615 Benchmark 1: sleep 1.0616 Time (mean ± σ): 1.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]617 Range (min … max): 1.000 s … 1.000 s 10 runs618619 Benchmark 2: sleep 2.0620 Time (mean ± σ): 2.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]621 Range (min … max): 2.000 s … 2.000 s 10 runs622623 Benchmark 3: sleep 3.0624 Time (mean ± σ): 3.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]625 Range (min … max): 3.000 s … 3.000 s 10 runs626627 Summary628 sleep 1.0 ran629 2.00 ± 0.00 times faster than sleep 2.0630 3.00 ± 0.00 times faster than sleep 3.0631632 ----- stderr -----633 ");Fix pipeline!David Peterbefore adoption8f20aed
lines 634–636why, one step back634}635636#[test]Change message for identical time and add test for itJan-Eric Nitschkebefore adoption13547e9
line 637why, one step back637fn shows_benchmark_comparison_with_same_time() {Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 638–640why, one step back638 let _settings = snapshot_settings().bind_to_scope();639 assert_cmd_snapshot!(hyperfine_debug()640 .arg("--style=basic")Change message for identical time and add test for itJan-Eric Nitschkebefore adoption13547e9
lines 641–645why, one step back641 .arg("--command-name=A")642 .arg("--command-name=B")643 .arg("sleep 1.0")644 .arg("sleep 1.0")645 .arg("sleep 2.0")Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 646–673why, one step back646 .arg("sleep 1000.0"), @r"647 success: true648 exit_code: 0649 ----- stdout -----650 Benchmark 1: A651 Time (mean ± σ): 1.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]652 Range (min … max): 1.000 s … 1.000 s 10 runs653654 Benchmark 2: B655 Time (mean ± σ): 1.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]656 Range (min … max): 1.000 s … 1.000 s 10 runs657658 Benchmark 3: sleep 2.0659 Time (mean ± σ): 2.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]660 Range (min … max): 2.000 s … 2.000 s 10 runs661662 Benchmark 4: sleep 1000.0663 Time (mean ± σ): 1000.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]664 Range (min … max): 1000.000 s … 1000.000 s 10 runs665666 Summary667 A ran668 As fast (1.00 ± 0.00) as B669 2.00 ± 0.00 times faster than sleep 2.0670 1000.00 ± 0.00 times faster than sleep 1000.0671672 ----- stderr -----673 ");Change message for identical time and add test for itJan-Eric Nitschkebefore adoption13547e9
lines 674–676why, one step back674}675676#[test]Fix prepare and conclude behaviour and add tests.Jan-Eric Nitschkebefore adoptiond4749b0
line 677why, one step back677fn shows_benchmark_comparison_relative_to_reference() {Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 678–680why, one step back678 let _settings = snapshot_settings().bind_to_scope();679 assert_cmd_snapshot!(hyperfine_debug()680 .arg("--style=basic")Fix prepare and conclude behaviour and add tests.Jan-Eric Nitschkebefore adoptiond4749b0
lines 681–682why, one step back681 .arg("--reference=sleep 2.0")682 .arg("sleep 1.0")Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 683–705why, one step back683 .arg("sleep 3.0"), @r"684 success: true685 exit_code: 0686 ----- stdout -----687 Benchmark 1: sleep 2.0688 Time (mean ± σ): 2.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]689 Range (min … max): 2.000 s … 2.000 s 10 runs690691 Benchmark 2: sleep 1.0692 Time (mean ± σ): 1.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]693 Range (min … max): 1.000 s … 1.000 s 10 runs694695 Benchmark 3: sleep 3.0696 Time (mean ± σ): 3.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]697 Range (min … max): 3.000 s … 3.000 s 10 runs698699 Summary700 sleep 2.0 ran701 2.00 ± 0.00 times slower than sleep 1.0702 1.50 ± 0.00 times faster than sleep 3.0703704 ----- stderr -----705 ");Fix prepare and conclude behaviour and add tests.Jan-Eric Nitschkebefore adoptiond4749b0
lines 706–708why, one step back706}707708#[test]Add option to name reference commandNiklas Dewallybefore adoption2166c9f
line 709why, one step back709fn shows_reference_name() {Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 710–712why, one step back710 let _settings = snapshot_settings().bind_to_scope();711 assert_cmd_snapshot!(hyperfine_debug()712 .arg("--style=basic")Add option to name reference commandNiklas Dewallybefore adoption2166c9f
lines 713–715why, one step back713 .arg("--reference=sleep 2.0")714 .arg("--reference-name=refabc123")715 .arg("sleep 1.0")Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 716–738why, one step back716 .arg("sleep 3.0"), @r"717 success: true718 exit_code: 0719 ----- stdout -----720 Benchmark 1: refabc123721 Time (mean ± σ): 2.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]722 Range (min … max): 2.000 s … 2.000 s 10 runs723724 Benchmark 2: sleep 1.0725 Time (mean ± σ): 1.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]726 Range (min … max): 1.000 s … 1.000 s 10 runs727728 Benchmark 3: sleep 3.0729 Time (mean ± σ): 3.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]730 Range (min … max): 3.000 s … 3.000 s 10 runs731732 Summary733 refabc123 ran734 2.00 ± 0.00 times slower than sleep 1.0735 1.50 ± 0.00 times faster than sleep 3.0736737 ----- stderr -----738 ");Add option to name reference commandNiklas Dewallybefore adoption2166c9f
lines 739–741why, one step back739}740741#[test]Fix pipeline!David Peterbefore adoption8f20aed
line 742why, one step back742fn performs_all_benchmarks_in_parameter_scan() {Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 743–745why, one step back743 let _settings = snapshot_settings().bind_to_scope();744 assert_cmd_snapshot!(hyperfine_debug()745 .arg("--style=basic")Fix pipeline!David Peterbefore adoption8f20aed
lines 746–751why, one step back746 .arg("--parameter-scan")747 .arg("time")748 .arg("30")749 .arg("45")750 .arg("--parameter-step-size")751 .arg("5")Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 752–779why, one step back752 .arg("sleep {time}"), @r"753 success: true754 exit_code: 0755 ----- stdout -----756 Benchmark 1: sleep 30757 Time (mean ± σ): 30.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]758 Range (min … max): 30.000 s … 30.000 s 10 runs759760 Benchmark 2: sleep 35761 Time (mean ± σ): 35.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]762 Range (min … max): 35.000 s … 35.000 s 10 runs763764 Benchmark 3: sleep 40765 Time (mean ± σ): 40.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]766 Range (min … max): 40.000 s … 40.000 s 10 runs767768 Benchmark 4: sleep 45769 Time (mean ± σ): 45.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]770 Range (min … max): 45.000 s … 45.000 s 10 runs771772 Summary773 sleep 30 ran774 1.17 ± 0.00 times faster than sleep 35775 1.33 ± 0.00 times faster than sleep 40776 1.50 ± 0.00 times faster than sleep 45777778 ----- stderr -----779 ");Fix prepare and conclude behaviour and add tests.Jan-Eric Nitschkebefore adoptiond4749b0
lines 780–782why, one step back780}781782#[test]Merge pull request #951 from Likio3000/codex/reject-negative-parameter-stepsDavid Peterbefore adoption862625f
lines 783–798why, one step back783fn rejects_negative_parameter_steps() {784 for step in ["-1", "-1.0"] {785 hyperfine()786 .args(["--parameter-scan", "n", "0", "1"])787 .arg(format!("--parameter-step-size={step}"))788 .arg("echo {n}")789 .assert()790 .code(1)791 .stdout(predicate::str::is_empty())792 .stderr(predicate::str::contains(793 "Parameter step size must be positive",794 ));795 }796}797798#[test]Fix prepare and conclude behaviour and add tests.Jan-Eric Nitschkebefore adoptiond4749b0
line 799why, one step back799fn performs_reference_and_all_benchmarks_in_parameter_scan() {Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 800–802why, one step back800 let _settings = snapshot_settings().bind_to_scope();801 assert_cmd_snapshot!(hyperfine_debug()802 .arg("--style=basic")Fix prepare and conclude behaviour and add tests.Jan-Eric Nitschkebefore adoptiond4749b0
lines 803–809why, one step back803 .arg("--reference=sleep 25")804 .arg("--parameter-scan")805 .arg("time")806 .arg("30")807 .arg("45")808 .arg("--parameter-step-size")809 .arg("5")Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 810–842why, one step back810 .arg("sleep {time}"), @r"811 success: true812 exit_code: 0813 ----- stdout -----814 Benchmark 1: sleep 25815 Time (mean ± σ): 25.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]816 Range (min … max): 25.000 s … 25.000 s 10 runs817818 Benchmark 2: sleep 30819 Time (mean ± σ): 30.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]820 Range (min … max): 30.000 s … 30.000 s 10 runs821822 Benchmark 3: sleep 35823 Time (mean ± σ): 35.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]824 Range (min … max): 35.000 s … 35.000 s 10 runs825826 Benchmark 4: sleep 40827 Time (mean ± σ): 40.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]828 Range (min … max): 40.000 s … 40.000 s 10 runs829830 Benchmark 5: sleep 45831 Time (mean ± σ): 45.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]832 Range (min … max): 45.000 s … 45.000 s 10 runs833834 Summary835 sleep 25 ran836 1.20 ± 0.00 times faster than sleep 30837 1.40 ± 0.00 times faster than sleep 35838 1.60 ± 0.00 times faster than sleep 40839 1.80 ± 0.00 times faster than sleep 45840841 ----- stderr -----842 ");Fix pipeline!David Peterbefore adoption8f20aed
line 843why, one step back843}Add regression test for #640David Peterbefore adoptionbf9644d
lines 844–846why, one step back844845#[test]846fn intermediate_results_are_not_exported_to_stdout() {Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 847–848why, one step back847 let _settings = snapshot_settings().bind_to_scope();848 assert_cmd_snapshot!(hyperfine_debug()Add regression test for #640David Peterbefore adoptionbf9644d
lines 849–852why, one step back849 .arg("--style=none") // To only see the Markdown export on stdout850 .arg("--export-markdown")851 .arg("-")852 .arg("sleep 1")Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 853–865why, one step back853 .arg("sleep 2"), @r"854 success: true855 exit_code: 0856 ----- stdout -----857858 | Command | Mean [s] | Min [s] | Max [s] | Relative |859 |:---|---:|---:|---:|---:|860 | `sleep 1` | 1.000 ± 0.000 | 1.000 | 1.000 | 1.00 |861 | `sleep 2` | 2.000 ± 0.000 | 2.000 | 2.000 | 2.00 ± 0.00 |862863864 ----- stderr -----865 ");Add regression test for #640David Peterbefore adoptionbf9644d
line 866why, one step back866}Add regression test for #642David Peterbefore adoption4b9cd06
lines 867–887why, one step back867868#[test]869#[cfg(unix)]870fn exports_intermediate_results_to_file() {871 use tempfile::tempdir;872873 let tempdir = tempdir().unwrap();874 let export_path = tempdir.path().join("results.md");875876 hyperfine()877 .arg("--runs=1")878 .arg("--export-markdown")879 .arg(&export_path)880 .arg("true")881 .arg("false")882 .assert()883 .failure();884885 let contents = std::fs::read_to_string(export_path).unwrap();886 assert!(contents.contains("true"));887}Show unused parameters in command namesDavid Peterbefore adoptiona875276
lines 888–889why, one step back888889#[test]Merge pull request #950 from Likio3000/codex/preserve-exports-on-invalid-optionsDavid Peterbefore adoptiond3d67fc
lines 890–932why, one step back890fn invalid_command_options_preserve_export_files() {891 use tempfile::tempdir;892893 for (option, values) in [894 ("--prepare", ["echo first", "echo second"]),895 ("--conclude", ["echo first", "echo second"]),896 ("--output", ["null", "pipe"]),897 ] {898 let directory = tempdir().unwrap();899 let existing_export = directory.path().join("previous.json");900 let new_export = directory.path().join("new.csv");901 let previous_results =902 b"{\"results\":[{\"command\":\"previous benchmark\",\"mean\":1.0}]}\n";903 std::fs::write(&existing_export, previous_results).unwrap();904905 hyperfine()906 .arg("--runs=1")907 .arg("--export-json")908 .arg(&existing_export)909 .arg("--export-csv")910 .arg(&new_export)911 .args([option, values[0], option, values[1]])912 .arg("echo benchmark")913 .assert()914 .failure()915 .stderr(predicate::str::contains(format!(916 "The '{option}' option has to be provided just once or N times"917 )));918919 assert_eq!(920 std::fs::read(&existing_export).unwrap(),921 previous_results,922 "{option} validation must preserve previous results"923 );924 assert!(925 !new_export.exists(),926 "{} validation must not create export files",927 option928 );929 }930}931932#[test]Merge pull request #947 from Likio3000/codex/fix-markdown-backticksDavid Peterbefore adoption0a61e33
lines 933–953why, one step back933fn markdown_export_preserves_backticks_and_pipes_in_command_names() {934 let _settings = snapshot_settings().bind_to_scope();935 assert_cmd_snapshot!(hyperfine_debug()936 .arg("--style=none")937 .arg("--export-markdown=-")938 .arg("--command-name=echo `uname` | cat")939 .arg("sleep 1"), @r"940 success: true941 exit_code: 0942 ----- stdout -----943944 | Command | Mean [s] | Min [s] | Max [s] | Relative |945 |:---|---:|---:|---:|---:|946 | `` echo `uname` \| cat `` | 1.000 ± 0.000 | 1.000 | 1.000 | 1.00 |947948949 ----- stderr -----950 ");951}952953#[test]Show unused parameters in command namesDavid Peterbefore adoptiona875276
lines 954–967why, one step back954fn unused_parameters_are_shown_in_benchmark_name() {955 hyperfine()956 .arg("--runs=2")957 .arg("--parameter-list")958 .arg("branch")959 .arg("master,feature")960 .arg("echo test")961 .assert()962 .success()963 .stdout(964 predicate::str::contains("echo test (branch = master)")965 .and(predicate::str::contains("echo test (branch = feature)")),966 );967}Add new --sort optionDavid Peterbefore adoptionac617c8
lines 968–970why, one step back968969#[test]970fn speed_comparison_sort_order() {Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 971–996why, one step back971 let _settings = snapshot_settings().bind_to_scope();972 insta::allow_duplicates! {973 for sort_order in ["auto", "mean-time"] {974 assert_cmd_snapshot!(hyperfine_debug()975 .arg("--style=basic")976 .arg("sleep 2")977 .arg("sleep 1")978 .arg(format!("--sort={sort_order}")), @r"979 success: true980 exit_code: 0981 ----- stdout -----982 Benchmark 1: sleep 2983 Time (mean ± σ): 2.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]984 Range (min … max): 2.000 s … 2.000 s 10 runs985986 Benchmark 2: sleep 1987 Time (mean ± σ): 1.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]988 Range (min … max): 1.000 s … 1.000 s 10 runs989990 Summary991 sleep 1 ran992 2.00 ± 0.00 times faster than sleep 2993994 ----- stderr -----995 ");996 }Add new --sort optionDavid Peterbefore adoptionac617c8
lines 997–998why, one step back997 }998Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 999–1000why, one step back999 assert_cmd_snapshot!(hyperfine_debug()1000 .arg("--style=basic")Add new --sort optionDavid Peterbefore adoptionac617c8
lines 1001–1002why, one step back1001 .arg("sleep 2")1002 .arg("sleep 1")Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 1003–1020why, one step back1003 .arg("--sort=command"), @r"1004 success: true1005 exit_code: 01006 ----- stdout -----1007 Benchmark 1: sleep 21008 Time (mean ± σ): 2.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]1009 Range (min … max): 2.000 s … 2.000 s 10 runs10101011 Benchmark 2: sleep 11012 Time (mean ± σ): 1.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]1013 Range (min … max): 1.000 s … 1.000 s 10 runs10141015 Relative speed comparison1016 2.00 ± 0.00 sleep 21017 1.00 sleep 110181019 ----- stderr -----1020 ");Add new --sort optionDavid Peterbefore adoptionac617c8
line 1021why, one step back1021}test: windows quote argPedro Witzelbefore adoption25331f8
lines 1022–1039why, one step back10221023#[cfg(windows)]1024#[test]1025fn windows_quote_args() {1026 hyperfine()1027 .arg("more \"example_input_file.txt\"")1028 .assert()1029 .success();1030}10311032#[cfg(windows)]1033#[test]1034fn windows_quote_before_quote_args() {1035 hyperfine()1036 .arg("dir \"..\\src\\\" \"..\\tests\\\"")1037 .assert()1038 .success();1039}Merge pull request #807 from willcl-ark/expose-run-varDavid Peterbefore adoption30a2b61
lines 1040–1081why, one step back10401041#[test]1042fn hyperfine_iteration_env_var_in_prepare_and_conclude_commands() {1043 let tempdir = tempfile::tempdir().unwrap();1044 let output_path = tempdir.path().join("iteration output.txt");1045 let iteration = if cfg!(windows) {1046 "%HYPERFINE_ITERATION%"1047 } else {1048 "$HYPERFINE_ITERATION"1049 };1050 let command = |phase| format!(r#"echo {phase}:{iteration} >> "iteration output.txt""#);10511052 hyperfine()1053 .current_dir(tempdir.path())1054 .arg("--runs=2")1055 .arg("--warmup=1")1056 .arg("--prepare")1057 .arg(command("prepare"))1058 .arg(command("benchmark"))1059 .arg("--conclude")1060 .arg(command("conclude"))1061 .assert()1062 .success();10631064 let contents = std::fs::read_to_string(output_path).unwrap();1065 // cmd.exe's echo includes the space before the redirection operator.1066 let lines: Vec<&str> = contents.lines().map(str::trim_end).collect();1067 assert_eq!(1068 lines,1069 [1070 "prepare:warmup-0",1071 "benchmark:warmup-0",1072 "conclude:warmup-0",1073 "prepare:0",1074 "benchmark:0",1075 "conclude:0",1076 "prepare:1",1077 "benchmark:1",1078 "conclude:1",1079 ]1080 );1081}