integration_tests.rs
This file
Path
tests/integration_tests.rs
1,274 lines · 36.4 KiB · Rust
Last changed by
Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
History of this fileTake it
The walk stopped after 200 commits: lines older than ab5ae5f point at it.
Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
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 clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
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 clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
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 clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
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 clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 38–53why, 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]48fn one_run_is_supported() {49 hyperfine()50 .arg("--runs=1")51 .arg("echo dummy benchmark")52 .assert()53 .success();Handle broken pipe errors on stdout gracefully (#932)jkbefore adoptionc0b3834
lines 54–94why, one step back54}5556/// Regression test: hyperfine must not panic when writing to a closed57/// stdout pipe (e.g. `hyperfine ... | head -n 1` or a downstream process58/// that terminates early). A `BrokenPipe` error should result in a quiet59/// exit with code 0 instead of a `println!` panic.60#[test]61fn exits_quietly_when_stdout_is_closed() {62 use std::process::Stdio;6364 for args in [65 vec!["--runs=1", "echo dummy benchmark"],66 vec!["--runs=1", "--export-json=-", "echo dummy benchmark"],67 vec!["--runs=1", "echo dummy benchmark", "echo second benchmark"],68 ] {69 // A pipe whose read end has been closed before hyperfine is even70 // started: every write to it will fail with `BrokenPipe`.71 let (reader, writer) = std::io::pipe().expect("failed to create pipe");72 drop(reader);7374 let output = hyperfine_raw_command()75 .args(&args)76 .stdout(writer)77 .stderr(Stdio::piped())78 .spawn()79 .expect("failed to spawn hyperfine")80 .wait_with_output()81 .expect("failed to wait for hyperfine");82 let stderr = String::from_utf8_lossy(&output.stderr);8384 assert!(85 !stderr.contains("panicked"),86 "hyperfine panicked while writing to a closed pipe:\n{}",87 stderr88 );89 assert!(90 output.status.success(),91 "hyperfine did not exit cleanly; stderr:\n{}",92 stderr93 );94 }Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 95–97why, one step back95}9697#[test]Fix panic on --runs 0 (#923)Vincentbefore adoption907de26
lines 98–113why, one step back98fn fails_with_zero_runs() {99 for option in ["--runs", "--min-runs", "--max-runs"] {100 hyperfine()101 .arg(option)102 .arg("0")103 .arg("echo dummy benchmark")104 .assert()105 .code(2)106 .stderr(predicate::str::contains(format!(107 "invalid value '0' for '{option} <NUM>'"108 )));109 }110}111112#[test]113fn min_runs_of_one_still_performs_one_run() {Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 114–117why, one step back114 let _settings = snapshot_settings().bind_to_scope();115 assert_cmd_snapshot!(hyperfine_debug()116 .arg("--style=basic")117 .arg("--metrics=time_wall_clock")Fix panic on --runs 0 (#923)Vincentbefore adoption907de26
lines 118–119why, one step back118 .arg("--min-runs=1")119 .arg("--warmup=0")Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 120–130why, one step back120 .arg("sleep 4"), @"121 success: true122 exit_code: 0123 ----- stdout -----124 Benchmark 1: sleep 4 (1 run)125 Value126 Wall Time 4.000 s127128129 ----- stderr -----130 ");Fix panic on --runs 0 (#923)Vincentbefore adoption907de26
lines 131–133why, one step back131}132133#[test]Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 134–168why, one step back134fn can_run_commands_without_a_shell() {135 hyperfine()136 .arg("--runs=1")137 .arg("--show-output")138 .arg("--shell=none")139 .arg("echo 'hello world' argument2")140 .assert()141 .success()142 .stdout(predicate::str::contains("hello world argument2"));143}144145#[test]146fn fails_with_wrong_number_of_command_name_arguments() {147 hyperfine()148 .arg("--command-name=a")149 .arg("--command-name=b")150 .arg("echo a")151 .assert()152 .failure()153 .stderr(predicate::str::contains("Too many --command-name options"));154}155156#[test]157fn fails_with_wrong_number_of_prepare_options() {158 hyperfine()159 .arg("--runs=1")160 .arg("--prepare=echo a")161 .arg("--prepare=echo b")162 .arg("echo a")163 .arg("echo b")164 .assert()165 .success();166167 hyperfine()168 .arg("--runs=1")Fix prepare and conclude behaviour and add tests.Jan-Eric Nitschkebefore adoptiond4749b0
line 169why, one step back169 .arg("--prepare=echo ref")Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 170–171why, one step back170 .arg("--prepare=echo a")171 .arg("--prepare=echo b")Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 172why, one step back172 .arg("echo ref")Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 173–174why, one step back173 .arg("echo a")174 .arg("echo b")Fix prepare and conclude behaviour and add tests.Jan-Eric Nitschkebefore adoptiond4749b0
lines 175–183why, one step back175 .assert()176 .success();177178 hyperfine()179 .arg("--runs=1")180 .arg("--prepare=echo a")181 .arg("--prepare=echo b")182 .arg("echo a")183 .arg("echo b")Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 184–189why, one step back184 .arg("echo c")185 .assert()186 .failure()187 .stderr(predicate::str::contains(188 "The '--prepare' option has to be provided",189 ));Fix prepare and conclude behaviour and add tests.Jan-Eric Nitschkebefore adoptiond4749b0
lines 190–194why, one step back190191 hyperfine()192 .arg("--runs=1")193 .arg("--prepare=echo a")194 .arg("--prepare=echo b")Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 195why, one step back195 .arg("echo ref")Fix prepare and conclude behaviour and add tests.Jan-Eric Nitschkebefore adoptiond4749b0
lines 196–202why, one step back196 .arg("echo a")197 .arg("echo b")198 .assert()199 .failure()200 .stderr(predicate::str::contains(201 "The '--prepare' option has to be provided",202 ));Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 203–205why, one step back203}204205#[test]Add --conclude option with testsJack O'Connorbefore adoptione13d0cb
lines 206–217why, one step back206fn fails_with_wrong_number_of_conclude_options() {207 hyperfine()208 .arg("--runs=1")209 .arg("--conclude=echo a")210 .arg("--conclude=echo b")211 .arg("echo a")212 .arg("echo b")213 .assert()214 .success();215216 hyperfine()217 .arg("--runs=1")Fix prepare and conclude behaviour and add tests.Jan-Eric Nitschkebefore adoptiond4749b0
line 218why, one step back218 .arg("--conclude=echo ref")Add --conclude option with testsJack O'Connorbefore adoptione13d0cb
lines 219–220why, one step back219 .arg("--conclude=echo a")220 .arg("--conclude=echo b")Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 221why, one step back221 .arg("echo ref")Add --conclude option with testsJack O'Connorbefore adoptione13d0cb
lines 222–223why, one step back222 .arg("echo a")223 .arg("echo b")Fix prepare and conclude behaviour and add tests.Jan-Eric Nitschkebefore adoptiond4749b0
lines 224–232why, one step back224 .assert()225 .success();226227 hyperfine()228 .arg("--runs=1")229 .arg("--conclude=echo a")230 .arg("--conclude=echo b")231 .arg("echo a")232 .arg("echo b")Add --conclude option with testsJack O'Connorbefore adoptione13d0cb
lines 233–238why, one step back233 .arg("echo c")234 .assert()235 .failure()236 .stderr(predicate::str::contains(237 "The '--conclude' option has to be provided",238 ));Fix prepare and conclude behaviour and add tests.Jan-Eric Nitschkebefore adoptiond4749b0
lines 239–243why, one step back239240 hyperfine()241 .arg("--runs=1")242 .arg("--conclude=echo a")243 .arg("--conclude=echo b")Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 244why, one step back244 .arg("echo ref")Fix prepare and conclude behaviour and add tests.Jan-Eric Nitschkebefore adoptiond4749b0
lines 245–251why, one step back245 .arg("echo a")246 .arg("echo b")247 .assert()248 .failure()249 .stderr(predicate::str::contains(250 "The '--conclude' option has to be provided",251 ));Add --conclude option with testsJack O'Connorbefore adoptione13d0cb
lines 252–254why, one step back252}253254#[test]Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 255–271why, one step back255fn fails_with_duplicate_parameter_names() {256 hyperfine()257 .arg("--parameter-list")258 .arg("x")259 .arg("1,2,3")260 .arg("--parameter-list")261 .arg("x")262 .arg("a,b,c")263 .arg("echo test")264 .assert()265 .failure()266 .stderr(predicate::str::contains("Duplicate parameter names: x"));267}268269#[test]270fn fails_for_unknown_command() {271 hyperfine()Make --shell=none the default (#982)David Peterbefore adoptionab86cb9
line 272why, one step back272 .arg("--shell=default")Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 273–311why, one step back273 .arg("--runs=1")274 .arg("some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577")275 .assert()276 .failure()277 .stderr(predicate::str::contains(278 "Command terminated with non-zero exit code",279 ));280}281282#[test]283fn fails_for_unknown_command_without_shell() {284 hyperfine()285 .arg("--shell=none")286 .arg("--runs=1")287 .arg("some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577")288 .assert()289 .failure()290 .stderr(predicate::str::contains(291 "Failed to run command 'some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577'",292 ));293}294295#[cfg(unix)]296#[test]297fn fails_for_failing_command_without_shell() {298 hyperfine()299 .arg("--shell=none")300 .arg("--runs=1")301 .arg("false")302 .assert()303 .failure()304 .stderr(predicate::str::contains(305 "Command terminated with non-zero exit code",306 ));307}308309#[test]310fn fails_for_unknown_setup_command() {311 hyperfine()Make --shell=none the default (#982)David Peterbefore adoptionab86cb9
line 312why, one step back312 .arg("--shell=default")Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 313–325why, one step back313 .arg("--runs=1")314 .arg("--setup=some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577")315 .arg("echo test")316 .assert()317 .failure()318 .stderr(predicate::str::contains(319 "The setup command terminated with a non-zero exit code.",320 ));321}322323#[test]324fn fails_for_unknown_cleanup_command() {325 hyperfine()Make --shell=none the default (#982)David Peterbefore adoptionab86cb9
line 326why, one step back326 .arg("--shell=default")Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 327–339why, one step back327 .arg("--runs=1")328 .arg("--cleanup=some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577")329 .arg("echo test")330 .assert()331 .failure()332 .stderr(predicate::str::contains(333 "The cleanup command terminated with a non-zero exit code.",334 ));335}336337#[test]338fn fails_for_unknown_prepare_command() {339 hyperfine()Make --shell=none the default (#982)David Peterbefore adoptionab86cb9
line 340why, one step back340 .arg("--shell=default")Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 341–349why, one step back341 .arg("--prepare=some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577")342 .arg("echo test")343 .assert()344 .failure()345 .stderr(predicate::str::contains(346 "The preparation command terminated with a non-zero exit code.",347 ));348}349Add --conclude option with testsJack O'Connorbefore adoptione13d0cb
lines 350–352why, one step back350#[test]351fn fails_for_unknown_conclude_command() {352 hyperfine()Make --shell=none the default (#982)David Peterbefore adoptionab86cb9
line 353why, one step back353 .arg("--shell=default")Add --conclude option with testsJack O'Connorbefore adoptione13d0cb
lines 354–362why, one step back354 .arg("--conclude=some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577")355 .arg("echo test")356 .assert()357 .failure()358 .stderr(predicate::str::contains(359 "The conclusion command terminated with a non-zero exit code.",360 ));361}362Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 363–381why, one step back363#[cfg(unix)]364#[test]365fn can_run_failing_commands_with_ignore_failure_option() {366 hyperfine()367 .arg("false")368 .assert()369 .failure()370 .stderr(predicate::str::contains(371 "Command terminated with non-zero exit code",372 ));373374 hyperfine()375 .arg("--runs=1")376 .arg("--ignore-failure")377 .arg("false")378 .assert()379 .success();380}381Support list of exit codes in --ignore-failureDavid Peterbefore adoptionb5a6860
lines 382–386why, one step back382#[cfg(unix)]383#[test]384fn can_ignore_specific_exit_codes() {385 // Test that specifying exit code 1 ignores it386 hyperfine()Make --shell=none the default (#982)David Peterbefore adoptionab86cb9
line 387why, one step back387 .arg("--shell=default")Support list of exit codes in --ignore-failureDavid Peterbefore adoptionb5a6860
lines 388–395why, one step back388 .arg("--runs=1")389 .arg("--ignore-failure=1")390 .arg("exit 1")391 .assert()392 .success();393394 // Test that other exit codes still fail395 hyperfine()Make --shell=none the default (#982)David Peterbefore adoptionab86cb9
line 396why, one step back396 .arg("--shell=default")Support list of exit codes in --ignore-failureDavid Peterbefore adoptionb5a6860
lines 397–411why, one step back397 .arg("--runs=1")398 .arg("--ignore-failure=1")399 .arg("exit 2")400 .assert()401 .failure()402 .stderr(predicate::str::contains(403 "Command terminated with non-zero exit code 2",404 ));405}406407#[cfg(unix)]408#[test]409fn can_ignore_multiple_exit_codes() {410 // Test that all specified exit codes are ignored411 hyperfine()Make --shell=none the default (#982)David Peterbefore adoptionab86cb9
line 412why, one step back412 .arg("--shell=default")Support list of exit codes in --ignore-failureDavid Peterbefore adoptionb5a6860
lines 413–419why, one step back413 .arg("--runs=1")414 .arg("--ignore-failure=1,2,3")415 .arg("exit 1")416 .assert()417 .success();418419 hyperfine()Make --shell=none the default (#982)David Peterbefore adoptionab86cb9
line 420why, one step back420 .arg("--shell=default")Support list of exit codes in --ignore-failureDavid Peterbefore adoptionb5a6860
lines 421–427why, one step back421 .arg("--runs=1")422 .arg("--ignore-failure=1,2,3")423 .arg("exit 2")424 .assert()425 .success();426427 hyperfine()Make --shell=none the default (#982)David Peterbefore adoptionab86cb9
line 428why, one step back428 .arg("--shell=default")Support list of exit codes in --ignore-failureDavid Peterbefore adoptionb5a6860
lines 429–436why, one step back429 .arg("--runs=1")430 .arg("--ignore-failure=1,2,3")431 .arg("exit 3")432 .assert()433 .success();434435 // Test that other exit codes still fail436 hyperfine()Make --shell=none the default (#982)David Peterbefore adoptionab86cb9
line 437why, one step back437 .arg("--shell=default")Support list of exit codes in --ignore-failureDavid Peterbefore adoptionb5a6860
lines 438–452why, one step back438 .arg("--runs=1")439 .arg("--ignore-failure=1,2,3")440 .arg("exit 4")441 .assert()442 .failure()443 .stderr(predicate::str::contains(444 "Command terminated with non-zero exit code 4",445 ));446}447448#[cfg(unix)]449#[test]450fn ignore_failure_with_all_non_zero() {451 // Test explicit "all-non-zero" mode452 hyperfine()Make --shell=none the default (#982)David Peterbefore adoptionab86cb9
line 453why, one step back453 .arg("--shell=default")Support list of exit codes in --ignore-failureDavid Peterbefore adoptionb5a6860
lines 454–460why, one step back454 .arg("--runs=1")455 .arg("--ignore-failure=all-non-zero")456 .arg("exit 5")457 .assert()458 .success();459}460Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 461–495why, one step back461#[test]462fn shows_output_of_benchmarked_command() {463 hyperfine()464 .arg("--runs=2")465 .arg("--command-name=dummy")466 .arg("--show-output")467 .arg("echo 4fd47015")468 .assert()469 .success()470 .stdout(predicate::str::contains("4fd47015").count(2));471}472473#[test]474fn runs_commands_using_user_defined_shell() {475 hyperfine()476 .arg("--runs=1")477 .arg("--show-output")478 .arg("--shell")479 .arg("echo 'custom_shell' '--shell-arg'")480 .arg("echo benchmark")481 .assert()482 .success()483 .stdout(484 predicate::str::contains("custom_shell --shell-arg -c echo benchmark").or(485 predicate::str::contains("custom_shell --shell-arg /C echo benchmark"),486 ),487 );488}489490#[test]491fn can_pass_input_to_command_from_a_file() {492 hyperfine()493 .arg("--runs=1")494 .arg("--input=example_input_file.txt")495 .arg("--show-output")fix(tests): restrict 'cat' tests to unix environments. Fixes #776 (#777)Ritvikbefore adoption3bd38f2
line 496why, one step back496 .arg(STDIN_READ_COMMAND)Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 497–507why, one step back497 .assert()498 .success()499 .stdout(predicate::str::contains("This text is part of a file"));500}501502#[test]503fn fails_if_invalid_stdin_data_file_provided() {504 hyperfine()505 .arg("--runs=1")506 .arg("--input=example_non_existent_file.txt")507 .arg("--show-output")fix(tests): restrict 'cat' tests to unix environments. Fixes #776 (#777)Ritvikbefore adoption3bd38f2
line 508why, one step back508 .arg(STDIN_READ_COMMAND)Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 509–521why, one step back509 .assert()510 .failure()511 .stderr(predicate::str::contains(512 "The file 'example_non_existent_file.txt' specified as '--input' does not exist",513 ));514}515516#[test]517fn returns_mean_time_in_correct_unit() {518 hyperfine_debug()519 .arg("sleep 1.234")520 .assert()521 .success()Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 522why, one step back522 .stdout(predicate::str::is_match(r"Wall Time\s+1\.234 s\s+±").unwrap());Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 523–527why, one step back523524 hyperfine_debug()525 .arg("sleep 0.123")526 .assert()527 .success()Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 528why, one step back528 .stdout(predicate::str::is_match(r"Wall Time\s+123\.0 ms\s+±").unwrap());Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 529–530why, one step back529530 hyperfine_debug()Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 531why, one step back531 .arg("--metrics=time_wall_clock:ms")Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 532–534why, one step back532 .arg("sleep 1.234")533 .assert()534 .success()Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 535why, one step back535 .stdout(predicate::str::is_match(r"Wall Time\s+1234\.0 ms\s+±").unwrap());Add support for microseconds, closes #684David Peterbefore adoption4564977
lines 536–537why, one step back536537 hyperfine_debug()Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 538why, one step back538 .arg("--metrics=time_wall_clock:us")Add support for microseconds, closes #684David Peterbefore adoption4564977
lines 539–541why, one step back539 .arg("sleep 1.234")540 .assert()541 .success()Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 542why, one step back542 .stdout(predicate::str::is_match(r"Wall Time\s+1234000\.0 µs\s+±").unwrap());Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 543–586why, one step back543}544545#[test]546fn performs_ten_runs_for_slow_commands() {547 hyperfine_debug()548 .arg("sleep 0.5")549 .assert()550 .success()551 .stdout(predicate::str::contains("10 runs"));552}553554#[test]555fn performs_three_seconds_of_benchmarking_for_fast_commands() {556 hyperfine_debug()557 .arg("sleep 0.01")558 .assert()559 .success()560 .stdout(predicate::str::contains("300 runs"));561}562563#[test]564fn takes_shell_spawning_time_into_account_for_computing_number_of_runs() {565 hyperfine_debug()566 .arg("--shell=sleep 0.02")567 .arg("sleep 0.01")568 .assert()569 .success()570 .stdout(predicate::str::contains("100 runs"));571}572573#[test]574fn takes_preparation_command_into_account_for_computing_number_of_runs() {575 hyperfine_debug()576 .arg("--prepare=sleep 0.02")577 .arg("sleep 0.01")578 .assert()579 .success()580 .stdout(predicate::str::contains("100 runs"));581582 // Shell overhead needs to be added to both the prepare command and the actual command,583 // leading to a total benchmark time of (prepare + shell + cmd + shell = 0.1 s)584 hyperfine_debug()585 .arg("--shell=sleep 0.01")586 .arg("--prepare=sleep 0.03")Add --conclude option with testsJack O'Connorbefore adoptione13d0cb
lines 587–628why, one step back587 .arg("sleep 0.05")588 .assert()589 .success()590 .stdout(predicate::str::contains("30 runs"));591}592593#[test]594fn takes_conclusion_command_into_account_for_computing_number_of_runs() {595 hyperfine_debug()596 .arg("--conclude=sleep 0.02")597 .arg("sleep 0.01")598 .assert()599 .success()600 .stdout(predicate::str::contains("100 runs"));601602 // Shell overhead needs to be added to both the conclude command and the actual command,603 // leading to a total benchmark time of (cmd + shell + conclude + shell = 0.1 s)604 hyperfine_debug()605 .arg("--shell=sleep 0.01")606 .arg("--conclude=sleep 0.03")607 .arg("sleep 0.05")608 .assert()609 .success()610 .stdout(predicate::str::contains("30 runs"));611}612613#[test]614fn takes_both_preparation_and_conclusion_command_into_account_for_computing_number_of_runs() {615 hyperfine_debug()616 .arg("--prepare=sleep 0.01")617 .arg("--conclude=sleep 0.01")618 .arg("sleep 0.01")619 .assert()620 .success()621 .stdout(predicate::str::contains("100 runs"));622623 // Shell overhead needs to be added to both the prepare, conclude and the actual command,624 // leading to a total benchmark time of (prepare + shell + cmd + shell + conclude + shell = 0.1 s)625 hyperfine_debug()626 .arg("--shell=sleep 0.01")627 .arg("--prepare=sleep 0.01")628 .arg("--conclude=sleep 0.01")Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 629–635why, one step back629 .arg("sleep 0.05")630 .assert()631 .success()632 .stdout(predicate::str::contains("30 runs"));633}634635#[test]Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 636–658why, one step back636fn secondary_metrics_include_factors_for_large_changes() {637 // Mock CPU time is zero; secondary wall time still gets ratio annotations.638 let output = hyperfine_debug()639 .args([640 "--metrics=time_cpu,time_wall_clock",641 "--style=basic",642 "--runs=2",643 "sleep 1",644 "sleep 10",645 "sleep 0.1",646 ])647 .output()648 .unwrap();649 assert!(output.status.success(), "{:?}", output);650 let stdout = String::from_utf8(output.stdout).unwrap();651 assert!(stdout.contains("+900.0%"), "{}", stdout);652 assert!(stdout.contains("-90.0%"), "{}", stdout);653 assert!(stdout.contains("+900.0% (10.0x slower)"), "{}", stdout);654 assert!(stdout.contains("-90.0% (10.0x faster)"), "{}", stdout);655}656657#[test]658fn shows_multiple_metrics_relative_to_first_command() {Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 659–661why, one step back659 let _settings = snapshot_settings().bind_to_scope();660 assert_cmd_snapshot!(hyperfine_debug()661 .arg("--style=basic")Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 662–665why, one step back662 .arg("--metrics=time_wall_clock:ms,time_user:us,memory_peak_resident:MiB")663 .arg("sleep 0.0817")664 .arg("sleep 0.6155")665 .arg("sleep 0.1707"), @"Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 666–668why, one step back666 success: true667 exit_code: 0668 ----- stdout -----Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 669–673why, one step back669 Benchmark 1: sleep 0.0817 (36 runs)670 mean ± σ min … max671 Wall Time 81.7 ms ± 0.0 ms 81.7 ms … 81.7 ms672 User time 0.0 µs ± 0.0 µs 0.0 µs … 0.0 µs673 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 674why, one step back674Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 675–679why, one step back675 Benchmark 2: sleep 0.6155 (10 runs)676 mean ± σ min … max677 Wall Time 615.5 ms ± 0.0 ms 615.5 ms … 615.5 ms +653.4% (7.5x slower)678 User time 0.0 µs ± 0.0 µs 0.0 µs … 0.0 µs N/A679 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 680why, one step back680Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 681–685why, one step back681 Benchmark 3: sleep 0.1707 (17 runs)682 mean ± σ min … max683 Wall Time 170.7 ms ± 0.0 ms 170.7 ms … 170.7 ms +108.9% (2.1x slower)684 User time 0.0 µs ± 0.0 µs 0.0 µs … 0.0 µs N/A685 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 686–689why, one step back686687688 ----- stderr -----689 ");Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 690–692why, one step back690}691692#[test]Change message for identical time and add test for itJan-Eric Nitschkebefore adoption13547e9
line 693why, one step back693fn shows_benchmark_comparison_with_same_time() {Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 694–695why, one step back694 let _settings = snapshot_settings().bind_to_scope();695 assert_cmd_snapshot!(hyperfine_debug()Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 696why, one step back696 .arg("--metrics=time_wall_clock,memory_peak_resident")Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
line 697why, one step back697 .arg("--style=basic")Change message for identical time and add test for itJan-Eric Nitschkebefore adoption13547e9
lines 698–702why, one step back698 .arg("--command-name=A")699 .arg("--command-name=B")700 .arg("sleep 1.0")701 .arg("sleep 1.0")702 .arg("sleep 2.0")Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 703why, one step back703 .arg("sleep 1000.0"), @"Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 704–706why, one step back704 success: true705 exit_code: 0706 ----- stdout -----Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 707–710why, one step back707 Benchmark 1: A (10 runs)708 mean ± σ min … max709 Wall Time 1.000 s ± 0.000 s 1.000 s … 1.000 s710 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 711why, one step back711Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 712–715why, one step back712 Benchmark 2: B (10 runs)713 mean ± σ min … max714 Wall Time 1.000 s ± 0.000 s 1.000 s … 1.000 s 0.0%715 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 716why, one step back716Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 717–720why, one step back717 Benchmark 3: sleep 2.0 (10 runs)718 mean ± σ min … max719 Wall Time 2.000 s ± 0.000 s 2.000 s … 2.000 s +100.0% (2.0x slower)720 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 721why, one step back721Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 722–725why, one step back722 Benchmark 4: sleep 1000.0 (10 runs)723 mean ± σ min … max724 Wall Time 1000.000 s ± 0.000 s 1000.000 s … 1000.000 s +99900.0% (1000.0x slower)725 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 726–729why, one step back726727728 ----- stderr -----729 ");Change message for identical time and add test for itJan-Eric Nitschkebefore adoption13547e9
lines 730–732why, one step back730}731732#[test]Fix prepare and conclude behaviour and add tests.Jan-Eric Nitschkebefore adoptiond4749b0
line 733why, one step back733fn shows_benchmark_comparison_relative_to_reference() {Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 734–735why, one step back734 let _settings = snapshot_settings().bind_to_scope();735 assert_cmd_snapshot!(hyperfine_debug()Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 736why, one step back736 .arg("--metrics=time_wall_clock,memory_peak_resident")Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
line 737why, one step back737 .arg("--style=basic")Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 738why, one step back738 .arg("sleep 2.0")Fix prepare and conclude behaviour and add tests.Jan-Eric Nitschkebefore adoptiond4749b0
line 739why, one step back739 .arg("sleep 1.0")Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 740why, one step back740 .arg("sleep 3.0"), @"Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 741–743why, one step back741 success: true742 exit_code: 0743 ----- stdout -----Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 744–747why, one step back744 Benchmark 1: sleep 2.0 (10 runs)745 mean ± σ min … max746 Wall Time 2.000 s ± 0.000 s 2.000 s … 2.000 s747 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 748why, one step back748Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 749–752why, one step back749 Benchmark 2: sleep 1.0 (10 runs)750 mean ± σ min … max751 Wall Time 1.000 s ± 0.000 s 1.000 s … 1.000 s -50.0% (2.0x faster)752 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 753why, one step back753Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 754–757why, one step back754 Benchmark 3: sleep 3.0 (10 runs)755 mean ± σ min … max756 Wall Time 3.000 s ± 0.000 s 3.000 s … 3.000 s +50.0% (1.5x slower)757 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 758–761why, one step back758759760 ----- stderr -----761 ");Fix prepare and conclude behaviour and add tests.Jan-Eric Nitschkebefore adoptiond4749b0
lines 762–764why, one step back762}763764#[test]Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 765why, one step back765fn comparison_and_markup_identify_first_command_as_reference() {Merge pull request #979 from sharkdp/fix/parameterized-referenceDavid Peterbefore adoption46e1f9f
lines 766–772why, one step back766 let _settings = snapshot_settings().bind_to_scope();767 let directory = tempfile::tempdir().unwrap();768 let export_path = directory.path().join("results.md");769 let output = hyperfine_debug()770 .args([771 "--style=basic",772 "--runs=1",Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 773why, one step back773 "--command-name=baseline",Merge pull request #979 from sharkdp/fix/parameterized-referenceDavid Peterbefore adoption46e1f9f
lines 774–776why, one step back774 "--export-markdown",775 ])776 .arg(&export_path)Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 777why, one step back777 .args(["sleep 2", "sleep 1", "sleep 2", "sleep 3"])Merge pull request #979 from sharkdp/fix/parameterized-referenceDavid Peterbefore adoption46e1f9f
lines 778–781why, one step back778 .output()779 .unwrap();780 assert!(output.status.success(), "{:?}", output);781 let stdout = String::from_utf8(output.stdout).unwrap();Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 782–789why, one step back782 assert!(783 stdout.contains("Benchmark 1: baseline (1 run)"),784 "{}",785 stdout786 );787 assert!(stdout.contains("-50.0%"), "{}", stdout);788 assert!(stdout.contains("0.0%"), "{}", stdout);789 assert!(stdout.contains("+50.0%"), "{}", stdout);Merge pull request #979 from sharkdp/fix/parameterized-referenceDavid Peterbefore adoption46e1f9f
line 790why, one step back790 let markdown = std::fs::read_to_string(export_path).unwrap();Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 791–797why, one step back791 insta::assert_snapshot!(markdown, @"792 | Command | Mean Wall Time [s] | Change | Factor |793 |:---|---:|---:|:---|794 | `baseline` | 2.000 | | |795 | `sleep 1` | 1.000 | -50.0% | (2.0x faster) |796 | `sleep 2` | 2.000 | 0.0% | |797 | `sleep 3` | 3.000 | +50.0% | (1.5x slower) |Merge pull request #979 from sharkdp/fix/parameterized-referenceDavid Peterbefore adoption46e1f9f
lines 798–805why, one step back798 ");799800 // Equal zero times have no meaningful relative factor.801 let output = hyperfine_debug()802 .args([803 "--style=none",804 "--runs=1",805 "--export-markdown=-",Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 806why, one step back806 "--command-name=baseline",Merge pull request #979 from sharkdp/fix/parameterized-referenceDavid Peterbefore adoption46e1f9f
lines 807–817why, one step back807 "sleep 0",808 "sleep 0",809 ])810 .output()811 .unwrap();812 assert!(output.status.success(), "{:?}", output);813 let markdown = String::from_utf8(output.stdout).unwrap();814 let row = markdown815 .lines()816 .find(|line| line.contains("sleep 0"))817 .unwrap();Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 818why, one step back818 assert!(row.ends_with("| N/A | |"), "{}", row);Merge pull request #979 from sharkdp/fix/parameterized-referenceDavid Peterbefore adoption46e1f9f
lines 819–821why, one step back819}820821#[test]Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
line 822why, one step back822fn performs_all_benchmarks_in_parameter_scan() {Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 823–824why, one step back823 let _settings = snapshot_settings().bind_to_scope();824 assert_cmd_snapshot!(hyperfine_debug()Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 825why, one step back825 .arg("--metrics=time_wall_clock,memory_peak_resident")Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
line 826why, one step back826 .arg("--style=basic")Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 827–832why, one step back827 .arg("--parameter-scan")828 .arg("time")829 .arg("30")830 .arg("45")831 .arg("--parameter-step-size")832 .arg("5")Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 833why, one step back833 .arg("sleep {time}"), @"Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 834–836why, one step back834 success: true835 exit_code: 0836 ----- stdout -----Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 837–840why, one step back837 Benchmark 1: sleep 30 (10 runs)838 mean ± σ min … max839 Wall Time 30.000 s ± 0.000 s 30.000 s … 30.000 s840 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 841why, one step back841Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 842–845why, one step back842 Benchmark 2: sleep 35 (10 runs)843 mean ± σ min … max844 Wall Time 35.000 s ± 0.000 s 35.000 s … 35.000 s +16.7%845 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 846why, one step back846Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 847–850why, one step back847 Benchmark 3: sleep 40 (10 runs)848 mean ± σ min … max849 Wall Time 40.000 s ± 0.000 s 40.000 s … 40.000 s +33.3% (1.3x slower)850 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 851why, one step back851Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 852–855why, one step back852 Benchmark 4: sleep 45 (10 runs)853 mean ± σ min … max854 Wall Time 45.000 s ± 0.000 s 45.000 s … 45.000 s +50.0% (1.5x slower)855 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 856–859why, one step back856857858 ----- stderr -----859 ");Fix prepare and conclude behaviour and add tests.Jan-Eric Nitschkebefore adoptiond4749b0
lines 860–862why, one step back860}861862#[test]Merge pull request #951 from Likio3000/codex/reject-negative-parameter-stepsDavid Peterbefore adoption862625f
lines 863–877why, one step back863fn rejects_negative_parameter_steps() {864 for step in ["-1", "-1.0"] {865 hyperfine()866 .args(["--parameter-scan", "n", "0", "1"])867 .arg(format!("--parameter-step-size={step}"))868 .arg("echo {n}")869 .assert()870 .code(1)871 .stdout(predicate::str::is_empty())872 .stderr(predicate::str::contains(873 "Parameter step size must be positive",874 ));875 }876}877Merge pull request #979 from sharkdp/fix/parameterized-referenceDavid Peterbefore adoption46e1f9f
line 878why, one step back878#[cfg(unix)]Merge pull request #951 from Likio3000/codex/reject-negative-parameter-stepsDavid Peterbefore adoption862625f
line 879why, one step back879#[test]Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 880why, one step back880fn preserves_input_order_with_parameterized_prepare() {Merge pull request #979 from sharkdp/fix/parameterized-referenceDavid Peterbefore adoption46e1f9f
lines 881–907why, one step back881 let directory = tempfile::tempdir().unwrap();882 let csv_path = directory.path().join("results.csv");883 let json_path = directory.path().join("results.json");884 let output = hyperfine_raw_command()885 .args([886 "--style=basic",887 "--shell=none",888 "--runs=1",889 "-L",890 "delay",891 "0.2,0.4,0.6",892 "--prepare",893 "sleep {delay}",894 "--export-csv",895 ])896 .arg(&csv_path)897 .arg("--export-json")898 .arg(&json_path)899 .arg("echo a")900 .output()901 .unwrap();902 assert!(output.status.success(), "{:?}", output);903 let stdout = String::from_utf8(output.stdout).unwrap();904 assert_eq!(stdout.matches("Benchmark ").count(), 3);905 for (number, delay) in ["0.2", "0.4", "0.6"].iter().enumerate() {906 assert!(907 stdout.contains(&format!(Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 908why, one step back908 "Benchmark {}: echo a (delay = {}) (1 run)",Merge pull request #979 from sharkdp/fix/parameterized-referenceDavid Peterbefore adoption46e1f9f
lines 909–915why, one step back909 number + 1,910 delay911 )),912 "{}",913 stdout914 );915 }Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 916–925why, one step back916 assert!(917 !stdout918 .split("Benchmark 2")919 .next()920 .unwrap()921 .contains("Change"),922 "{}",923 stdout924 );925 assert!(!stdout.contains("Change vs #1"));Merge pull request #979 from sharkdp/fix/parameterized-referenceDavid Peterbefore adoption46e1f9f
lines 926–943why, one step back926927 let mut csv = csv::Reader::from_path(csv_path).unwrap();928 assert!(csv929 .headers()930 .unwrap()931 .iter()932 .any(|header| header == "parameter_delay"));933 assert_eq!(934 csv.records().collect::<Result<Vec<_>, _>>().unwrap().len(),935 3936 );937 let json: serde_json::Value =938 serde_json::from_slice(&std::fs::read(json_path).unwrap()).unwrap();939 let results = json["results"].as_array().unwrap();940 assert_eq!(results.len(), 3);941 assert_eq!(942 results943 .iter()Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
line 944why, one step back944 .map(|result| result["parameters"]["delay"]["value"].as_str().unwrap())Merge pull request #979 from sharkdp/fix/parameterized-referenceDavid Peterbefore adoption46e1f9f
lines 945–950why, one step back945 .collect::<Vec<_>>(),946 ["0.2", "0.4", "0.6"]947 );948}949950#[test]Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 951why, one step back951fn rejects_invalid_metric_before_export_or_setup() {Merge pull request #979 from sharkdp/fix/parameterized-referenceDavid Peterbefore adoption46e1f9f
lines 952–957why, one step back952 let directory = tempfile::tempdir().unwrap();953 let export_path = directory.path().join("results.csv");954 let marker_path = directory.path().join("setup-ran");955 std::fs::write(&export_path, "previous contents").unwrap();956957 hyperfine()Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 958–965why, one step back958 .args([959 "--metrics=memory_peak_resident:ms",960 "-P",961 "secs",962 "2",963 "3",964 "--setup",965 ])Merge pull request #979 from sharkdp/fix/parameterized-referenceDavid Peterbefore adoption46e1f9f
lines 966–973why, one step back966 .arg(format!("echo touched > \"{}\"", marker_path.display()))967 .arg("--export-csv")968 .arg(&export_path)969 .arg("sleep {secs}")970 .assert()971 .failure()972 .stdout(predicate::str::is_empty())973 .stderr(predicate::str::contains(Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 974why, one step back974 "Unit 'ms' is not valid for metric 'memory_peak_resident'",Merge pull request #979 from sharkdp/fix/parameterized-referenceDavid Peterbefore adoption46e1f9f
lines 975–984why, one step back975 ));976 assert_eq!(977 std::fs::read_to_string(export_path).unwrap(),978 "previous contents"979 );980 assert!(!marker_path.exists());981}982983#[cfg(unix)]984#[test]Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 985why, one step back985fn intermediate_markdown_retains_completed_reference() {Merge pull request #979 from sharkdp/fix/parameterized-referenceDavid Peterbefore adoption46e1f9f
lines 986–1012why, one step back986 let directory = tempfile::tempdir().unwrap();987 let export_path = directory.path().join("results.md");988 hyperfine()989 .args([990 "--style=none",991 "--shell=none",992 "--runs=1",993 "-L",994 "delay",995 "0.01,0.02,0.03",996 "--prepare",997 "true",998 "--prepare",999 "false",1000 "--prepare",1001 "true",1002 "--export-markdown",1003 ])1004 .arg(&export_path)1005 .arg("sleep {delay}")1006 .assert()1007 .failure();1008 let markdown = std::fs::read_to_string(export_path).unwrap();1009 let row = markdown1010 .lines()1011 .find(|line| line.contains("sleep 0.01"))1012 .unwrap();Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 1013why, one step back1013 assert!(row.ends_with("| | |"), "{}", row);Merge pull request #979 from sharkdp/fix/parameterized-referenceDavid Peterbefore adoption46e1f9f
lines 1014–1016why, one step back1014}10151016#[test]Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 1017why, one step back1017fn markdown_export_uses_first_parameterized_benchmark_as_reference() {Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 1018–1019why, one step back1018 let _settings = snapshot_settings().bind_to_scope();1019 assert_cmd_snapshot!(hyperfine_debug()Merge pull request #979 from sharkdp/fix/parameterized-referenceDavid Peterbefore adoption46e1f9f
lines 1020–1030why, one step back1020 .args([1021 "--style=none",1022 "--runs=1",1023 "--export-markdown=-",1024 "-P",1025 "x",1026 "1",1027 "3",1028 "--command-name",1029 "case-{x}",1030 "sleep {x}",Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 1031why, one step back1031 ]), @"Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 1032–1035why, one step back1032 success: true1033 exit_code: 01034 ----- stdout -----1035Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 1036–1040why, one step back1036 | Command | Mean Wall Time [s] | Change | Factor |1037 |:---|---:|---:|:---|1038 | `case-1` | 1.000 | | |1039 | `case-2` | 2.000 | +100.0% | (2.0x slower) |1040 | `case-3` | 3.000 | +200.0% | (3.0x slower) |Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 1041–1044why, one step back104110421043 ----- stderr -----1044 ");Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 1045–1048why, one step back1045}10461047#[test]1048fn intermediate_results_are_not_exported_to_stdout() {Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 1049–1050why, one step back1049 let _settings = snapshot_settings().bind_to_scope();1050 assert_cmd_snapshot!(hyperfine_debug()Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 1051–1054why, one step back1051 .arg("--style=none") // To only see the Markdown export on stdout1052 .arg("--export-markdown")1053 .arg("-")1054 .arg("sleep 1")Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 1055why, one step back1055 .arg("sleep 2"), @"Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 1056–1059why, one step back1056 success: true1057 exit_code: 01058 ----- stdout -----1059Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 1060–1063why, one step back1060 | Command | Mean Wall Time [s] | Change | Factor |1061 |:---|---:|---:|:---|1062 | `sleep 1` | 1.000 ± 0.000 | | |1063 | `sleep 2` | 2.000 ± 0.000 | +100.0% | (2.0x slower) |Merge pull request #956 from sharkdp/codex/inline-snapshot-testsDavid Peterbefore adoption73cf51e
lines 1064–1067why, one step back106410651066 ----- stderr -----1067 ");Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 1068–1091why, one step back1068}10691070#[test]1071#[cfg(unix)]1072fn exports_intermediate_results_to_file() {1073 use tempfile::tempdir;10741075 let tempdir = tempdir().unwrap();1076 let export_path = tempdir.path().join("results.md");10771078 hyperfine()1079 .arg("--runs=1")1080 .arg("--export-markdown")1081 .arg(&export_path)1082 .arg("true")1083 .arg("false")1084 .assert()1085 .failure();10861087 let contents = std::fs::read_to_string(export_path).unwrap();1088 assert!(contents.contains("true"));1089}10901091#[test]Merge pull request #950 from Likio3000/codex/preserve-exports-on-invalid-optionsDavid Peterbefore adoptiond3d67fc
lines 1092–1134why, one step back1092fn invalid_command_options_preserve_export_files() {1093 use tempfile::tempdir;10941095 for (option, values) in [1096 ("--prepare", ["echo first", "echo second"]),1097 ("--conclude", ["echo first", "echo second"]),1098 ("--output", ["null", "pipe"]),1099 ] {1100 let directory = tempdir().unwrap();1101 let existing_export = directory.path().join("previous.json");1102 let new_export = directory.path().join("new.csv");1103 let previous_results =1104 b"{\"results\":[{\"command\":\"previous benchmark\",\"mean\":1.0}]}\n";1105 std::fs::write(&existing_export, previous_results).unwrap();11061107 hyperfine()1108 .arg("--runs=1")1109 .arg("--export-json")1110 .arg(&existing_export)1111 .arg("--export-csv")1112 .arg(&new_export)1113 .args([option, values[0], option, values[1]])1114 .arg("echo benchmark")1115 .assert()1116 .failure()1117 .stderr(predicate::str::contains(format!(1118 "The '{option}' option has to be provided just once or N times"1119 )));11201121 assert_eq!(1122 std::fs::read(&existing_export).unwrap(),1123 previous_results,1124 "{option} validation must preserve previous results"1125 );1126 assert!(1127 !new_export.exists(),1128 "{} validation must not create export files",1129 option1130 );1131 }1132}11331134#[test]Merge pull request #947 from Likio3000/codex/fix-markdown-backticksDavid Peterbefore adoption0a61e33
lines 1135–1145why, one step back1135fn markdown_export_preserves_backticks_and_pipes_in_command_names() {1136 let _settings = snapshot_settings().bind_to_scope();1137 assert_cmd_snapshot!(hyperfine_debug()1138 .arg("--style=none")1139 .arg("--export-markdown=-")1140 .arg("--command-name=echo `uname` | cat")1141 .arg("sleep 1"), @r"1142 success: true1143 exit_code: 01144 ----- stdout -----1145Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 1146–1148why, one step back1146 | Command | Mean Wall Time [s] | Change | Factor |1147 |:---|---:|---:|:---|1148 | `` echo `uname` \| cat `` | 1.000 ± 0.000 | | |Merge pull request #947 from Likio3000/codex/fix-markdown-backticksDavid Peterbefore adoption0a61e33
lines 1149–1155why, one step back114911501151 ----- stderr -----1152 ");1153}11541155#[test]Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 1156–1169why, one step back1156fn unused_parameters_are_shown_in_benchmark_name() {1157 hyperfine()1158 .arg("--runs=2")1159 .arg("--parameter-list")1160 .arg("branch")1161 .arg("master,feature")1162 .arg("echo test")1163 .assert()1164 .success()1165 .stdout(1166 predicate::str::contains("echo test (branch = master)")1167 .and(predicate::str::contains("echo test (branch = feature)")),1168 );1169}Add new --sort optionDavid Peterbefore adoptionac617c8
line 1170why, one step back1170test: windows quote argPedro Witzelbefore adoption25331f8
lines 1171–1174why, one step back1171#[cfg(windows)]1172#[test]1173fn windows_quote_args() {1174 hyperfine()Make --shell=none the default (#982)David Peterbefore adoptionab86cb9
line 1175why, one step back1175 .arg("--shell=default")test: windows quote argPedro Witzelbefore adoption25331f8
lines 1176–1184why, one step back1176 .arg("more \"example_input_file.txt\"")1177 .assert()1178 .success();1179}11801181#[cfg(windows)]1182#[test]1183fn windows_quote_before_quote_args() {1184 hyperfine()Make --shell=none the default (#982)David Peterbefore adoptionab86cb9
line 1185why, one step back1185 .arg("--shell=default")test: windows quote argPedro Witzelbefore adoption25331f8
lines 1186–1189why, one step back1186 .arg("dir \"..\\src\\\" \"..\\tests\\\"")1187 .assert()1188 .success();1189}Merge pull request #807 from willcl-ark/expose-run-varDavid Peterbefore adoption30a2b61
lines 1190–1202why, one step back11901191#[test]1192fn hyperfine_iteration_env_var_in_prepare_and_conclude_commands() {1193 let tempdir = tempfile::tempdir().unwrap();1194 let output_path = tempdir.path().join("iteration output.txt");1195 let iteration = if cfg!(windows) {1196 "%HYPERFINE_ITERATION%"1197 } else {1198 "$HYPERFINE_ITERATION"1199 };1200 let command = |phase| format!(r#"echo {phase}:{iteration} >> "iteration output.txt""#);12011202 hyperfine()Make --shell=none the default (#982)David Peterbefore adoptionab86cb9
line 1203why, one step back1203 .arg("--shell=default")Merge pull request #807 from willcl-ark/expose-run-varDavid Peterbefore adoption30a2b61
lines 1204–1231why, one step back1204 .current_dir(tempdir.path())1205 .arg("--runs=2")1206 .arg("--warmup=1")1207 .arg("--prepare")1208 .arg(command("prepare"))1209 .arg(command("benchmark"))1210 .arg("--conclude")1211 .arg(command("conclude"))1212 .assert()1213 .success();12141215 let contents = std::fs::read_to_string(output_path).unwrap();1216 // cmd.exe's echo includes the space before the redirection operator.1217 let lines: Vec<&str> = contents.lines().map(str::trim_end).collect();1218 assert_eq!(1219 lines,1220 [1221 "prepare:warmup-0",1222 "benchmark:warmup-0",1223 "conclude:warmup-0",1224 "prepare:0",1225 "benchmark:0",1226 "conclude:0",1227 "prepare:1",1228 "benchmark:1",1229 "conclude:1",1230 ]1231 );Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
lines 1232–1241why, one step back1232}12331234#[test]1235fn json_export_basic() {1236 let _settings = json_snapshot_settings().bind_to_scope();1237 assert_cmd_snapshot!(hyperfine_debug().args([1238 "--style=none",1239 "--export-json=-",1240 "--runs=2",1241 "--warmup=1",Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 1242–1243why, one step back1242 "--command-name=one second",1243 "sleep 1",Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
lines 1244–1273why, one step back1244 "--command-name=sleep 2",1245 "sleep 2",1246 ]));1247}12481249#[test]1250fn json_export_single_run() {1251 // Make sure that the standard deviation is set to `null`1252 let _settings = json_snapshot_settings().bind_to_scope();1253 assert_cmd_snapshot!(hyperfine_debug().args([1254 "--style=none",1255 "--export-json=-",1256 "--runs=1",1257 "sleep 1",1258 ]));1259}12601261#[test]1262fn json_export_parameterized_with_reference() {1263 let _settings = json_snapshot_settings().bind_to_scope();1264 assert_cmd_snapshot!(hyperfine_debug().args([1265 "--style=none",1266 "--export-json=-",1267 "--runs=2",1268 "-L",1269 "duration",1270 "1,2",1271 "--command-name=sleep for {duration} seconds",1272 "sleep {duration}",1273 ]));Merge pull request #807 from willcl-ark/expose-run-varDavid Peterbefore adoption30a2b61
line 1274why, one step back1274}