Skip to content
Myr

Use inline snapshots for execution logs and benchmark reports

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Peter · committed by David Peter · parent 258af07 · Browse files · 2 files+517 added−343 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+517 added−343 removed

  • tests:+517 added−343 removed

2 files+517 added−343 removed

modified:tests/execution_order_tests.rs+304 added-281 removed
1use std::{fs::File, io::Read, path::PathBuf};1use std::{fs, path::PathBuf};23use tempfile::{tempdir, TempDir};45mod common;6use common::hyperfine;78struct ExecutionOrderTest {9 cmd: assert_cmd::Command,10 expected_content: String,10 logfile_path: PathBuf,11 #[allow(dead_code)]12 tempdir: TempDir,13}
4 unmodified lines
18 let logfile_path = tempdir.path().join("output.log");1920 ExecutionOrderTest {21 cmd: hyperfine(),23 expected_content: String::new(),22 logfile_path,23 tempdir,24 }25 }
40 unmodified lines
66 self.arg("--cleanup");67 self.command(output)68 }6972 fn expect_output(&mut self, output: &str) -> &mut Self {73 self.expected_content.push_str(output);70 fn run(&mut self) -> String {71 self.cmd.assert().success();7273 let content = fs::read_to_string(&self.logfile_path).unwrap();74 // cmd.exe's echo includes the space before redirection and uses CRLF.75 #[cfg(windows)]76 {77 self.expected_content.push_str(" \r");78 }7980 self.expected_content.push('\n');81 self76 let content = content.replace(" \r\n", "\n");77 content78 }8384 fn run(&mut self) {85 self.cmd.assert().success();8687 let mut f = File::open(&self.logfile_path).unwrap();88 let mut content = String::new();89 f.read_to_string(&mut content).unwrap();9091 assert_eq!(content, self.expected_content);92 }79}8081impl Default for ExecutionOrderTest {82 fn default() -> Self {
2 unmodified lines
85}8687#[test]88fn benchmarks_are_executed_sequentially_one() {103 ExecutionOrderTest::new()89 let output = ExecutionOrderTest::new()90 .arg("--runs=1")91 .command("command 1")92 .command("command 2")107 .expect_output("command 1")108 .expect_output("command 2")93 .run();9495 insta::assert_snapshot!(output, @r"96 command 197 command 298 ");99}100101#[test]102fn benchmarks_are_executed_sequentially() {114 ExecutionOrderTest::new()103 let output = ExecutionOrderTest::new()104 .arg("--runs=2")105 .command("command 1")106 .command("command 2")118 .expect_output("command 1")119 .expect_output("command 1")120 .expect_output("command 2")121 .expect_output("command 2")107 .run();108109 insta::assert_snapshot!(output, @r"110 command 1111 command 1112 command 2113 command 2114 ");115}116117#[test]118fn warmup_runs_are_executed_before_benchmarking_runs() {127 ExecutionOrderTest::new()119 let output = ExecutionOrderTest::new()120 .arg("--runs=2")121 .arg("--warmup=3")122 .command("command 1")131 .expect_output("command 1")132 .expect_output("command 1")133 .expect_output("command 1")134 .expect_output("command 1")135 .expect_output("command 1")123 .run();124125 insta::assert_snapshot!(output, @r"126 command 1127 command 1128 command 1129 command 1130 command 1131 ");132}133134#[test]135fn setup_commands_are_executed_before_each_series_of_timing_runs() {141 ExecutionOrderTest::new()136 let output = ExecutionOrderTest::new()137 .arg("--runs=2")138 .setup("setup")139 .command("command 1")140 .command("command 2")146 .expect_output("setup")147 .expect_output("command 1")148 .expect_output("command 1")149 .expect_output("setup")150 .expect_output("command 2")151 .expect_output("command 2")141 .run();142143 insta::assert_snapshot!(output, @r"144 setup145 command 1146 command 1147 setup148 command 2149 command 2150 ");151}152153#[test]154fn prepare_commands_are_executed_before_each_timing_run() {157 ExecutionOrderTest::new()155 let output = ExecutionOrderTest::new()156 .arg("--runs=2")157 .prepare("prepare")158 .command("command 1")159 .command("command 2")162 .expect_output("prepare")163 .expect_output("command 1")164 .expect_output("prepare")165 .expect_output("command 1")166 .expect_output("prepare")167 .expect_output("command 2")168 .expect_output("prepare")169 .expect_output("command 2")160 .run();161162 insta::assert_snapshot!(output, @r"163 prepare164 command 1165 prepare166 command 1167 prepare168 command 2169 prepare170 command 2171 ");172}173174#[test]175fn conclude_commands_are_executed_after_each_timing_run() {175 ExecutionOrderTest::new()176 let output = ExecutionOrderTest::new()177 .arg("--runs=2")178 .conclude("conclude")179 .command("command 1")180 .command("command 2")180 .expect_output("command 1")181 .expect_output("conclude")182 .expect_output("command 1")183 .expect_output("conclude")184 .expect_output("command 2")185 .expect_output("conclude")186 .expect_output("command 2")187 .expect_output("conclude")181 .run();182183 insta::assert_snapshot!(output, @r"184 command 1185 conclude186 command 1187 conclude188 command 2189 conclude190 command 2191 conclude192 ");193}194195#[test]196fn prepare_commands_are_executed_before_each_warmup() {193 ExecutionOrderTest::new()197 let output = ExecutionOrderTest::new()198 .arg("--warmup=2")199 .arg("--runs=1")200 .prepare("prepare")201 .command("command 1")202 .command("command 2")199 // warmup 1200 .expect_output("prepare")201 .expect_output("command 1")202 .expect_output("prepare")203 .expect_output("command 1")204 // benchmark 1205 .expect_output("prepare")206 .expect_output("command 1")207 // warmup 2208 .expect_output("prepare")209 .expect_output("command 2")210 .expect_output("prepare")211 .expect_output("command 2")212 // benchmark 2213 .expect_output("prepare")214 .expect_output("command 2")203 .run();204205 insta::assert_snapshot!(output, @r"206 prepare207 command 1208 prepare209 command 1210 prepare211 command 1212 prepare213 command 2214 prepare215 command 2216 prepare217 command 2218 ");219}220221#[test]222fn conclude_commands_are_executed_after_each_warmup() {220 ExecutionOrderTest::new()223 let output = ExecutionOrderTest::new()224 .arg("--warmup=2")225 .arg("--runs=1")226 .conclude("conclude")227 .command("command 1")228 .command("command 2")226 // warmup 1227 .expect_output("command 1")228 .expect_output("conclude")229 .expect_output("command 1")230 .expect_output("conclude")231 // benchmark 1232 .expect_output("command 1")233 .expect_output("conclude")234 // warmup 2235 .expect_output("command 2")236 .expect_output("conclude")237 .expect_output("command 2")238 .expect_output("conclude")239 // benchmark 2240 .expect_output("command 2")241 .expect_output("conclude")229 .run();230231 insta::assert_snapshot!(output, @r"232 command 1233 conclude234 command 1235 conclude236 command 1237 conclude238 command 2239 conclude240 command 2241 conclude242 command 2243 conclude244 ");245}246247#[test]248fn cleanup_commands_are_executed_once_after_each_benchmark() {247 ExecutionOrderTest::new()249 let output = ExecutionOrderTest::new()250 .arg("--runs=2")251 .cleanup("cleanup")252 .command("command 1")253 .command("command 2")252 .expect_output("command 1")253 .expect_output("command 1")254 .expect_output("cleanup")255 .expect_output("command 2")256 .expect_output("command 2")257 .expect_output("cleanup")254 .run();255256 insta::assert_snapshot!(output, @r"257 command 1258 command 1259 cleanup260 command 2261 command 2262 cleanup263 ");264}265266#[test]267fn setup_prepare_cleanup_combined() {263 ExecutionOrderTest::new()268 let output = ExecutionOrderTest::new()269 .arg("--warmup=1")270 .arg("--runs=2")271 .setup("setup")272 .prepare("prepare")273 .command("command1")274 .command("command2")275 .cleanup("cleanup")271 // 1272 .expect_output("setup")273 .expect_output("prepare")274 .expect_output("command1")275 .expect_output("prepare")276 .expect_output("command1")277 .expect_output("prepare")278 .expect_output("command1")279 .expect_output("cleanup")280 // 2281 .expect_output("setup")282 .expect_output("prepare")283 .expect_output("command2")284 .expect_output("prepare")285 .expect_output("command2")286 .expect_output("prepare")287 .expect_output("command2")288 .expect_output("cleanup")276 .run();277278 insta::assert_snapshot!(output, @r"279 setup280 prepare281 command1282 prepare283 command1284 prepare285 command1286 cleanup287 setup288 prepare289 command2290 prepare291 command2292 prepare293 command2294 cleanup295 ");296}297298#[test]299fn setup_prepare_conclude_cleanup_combined() {294 ExecutionOrderTest::new()300 let output = ExecutionOrderTest::new()301 .arg("--warmup=1")302 .arg("--runs=2")303 .setup("setup")304 .prepare("prepare")305 .command("command1")306 .command("command2")307 .conclude("conclude")308 .cleanup("cleanup")303 // 1304 .expect_output("setup")305 .expect_output("prepare")306 .expect_output("command1")307 .expect_output("conclude")308 .expect_output("prepare")309 .expect_output("command1")310 .expect_output("conclude")311 .expect_output("prepare")312 .expect_output("command1")313 .expect_output("conclude")314 .expect_output("cleanup")315 // 2316 .expect_output("setup")317 .expect_output("prepare")318 .expect_output("command2")319 .expect_output("conclude")320 .expect_output("prepare")321 .expect_output("command2")322 .expect_output("conclude")323 .expect_output("prepare")324 .expect_output("command2")325 .expect_output("conclude")326 .expect_output("cleanup")309 .run();310311 insta::assert_snapshot!(output, @r"312 setup313 prepare314 command1315 conclude316 prepare317 command1318 conclude319 prepare320 command1321 conclude322 cleanup323 setup324 prepare325 command2326 conclude327 prepare328 command2329 conclude330 prepare331 command2332 conclude333 cleanup334 ");335}336337#[test]338fn single_parameter_value() {332 ExecutionOrderTest::new()339 let output = ExecutionOrderTest::new()340 .arg("--runs=2")341 .arg("--parameter-list")342 .arg("number")343 .arg("1,2,3")344 .command("command {number}")338 .expect_output("command 1")339 .expect_output("command 1")340 .expect_output("command 2")341 .expect_output("command 2")342 .expect_output("command 3")343 .expect_output("command 3")345 .run();346347 insta::assert_snapshot!(output, @r"348 command 1349 command 1350 command 2351 command 2352 command 3353 command 3354 ");355}356357#[test]358fn multiple_parameter_values() {349 ExecutionOrderTest::new()359 let output = ExecutionOrderTest::new()360 .arg("--runs=2")361 .arg("--parameter-list")362 .arg("number")363 .arg("1,2,3")364 .arg("--parameter-list")365 .arg("letter")366 .arg("a,b")367 .command("command {number} {letter}")358 .expect_output("command 1 a")359 .expect_output("command 1 a")360 .expect_output("command 2 a")361 .expect_output("command 2 a")362 .expect_output("command 3 a")363 .expect_output("command 3 a")364 .expect_output("command 1 b")365 .expect_output("command 1 b")366 .expect_output("command 2 b")367 .expect_output("command 2 b")368 .expect_output("command 3 b")369 .expect_output("command 3 b")368 .run();369370 insta::assert_snapshot!(output, @r"371 command 1 a372 command 1 a373 command 2 a374 command 2 a375 command 3 a376 command 3 a377 command 1 b378 command 1 b379 command 2 b380 command 2 b381 command 3 b382 command 3 b383 ");384}385386#[test]387fn reference_is_executed_first() {375 ExecutionOrderTest::new()388 let output = ExecutionOrderTest::new()389 .arg("--runs=1")390 .reference("reference")391 .command("command 1")392 .command("command 2")380 .expect_output("reference")381 .expect_output("command 1")382 .expect_output("command 2")393 .run();394395 insta::assert_snapshot!(output, @r"396 reference397 command 1398 command 2399 ");400}401402#[test]403fn reference_is_executed_first_parameter_value() {388 ExecutionOrderTest::new()404 let output = ExecutionOrderTest::new()405 .arg("--runs=2")406 .reference("reference")407 .arg("--parameter-list")408 .arg("number")409 .arg("1,2,3")410 .command("command {number}")395 .expect_output("reference")396 .expect_output("reference")397 .expect_output("command 1")398 .expect_output("command 1")399 .expect_output("command 2")400 .expect_output("command 2")401 .expect_output("command 3")402 .expect_output("command 3")411 .run();412413 insta::assert_snapshot!(output, @r"414 reference415 reference416 command 1417 command 1418 command 2419 command 2420 command 3421 command 3422 ");423}424425#[test]426fn reference_is_executed_separately_from_commands() {408 ExecutionOrderTest::new()427 let output = ExecutionOrderTest::new()428 .arg("--runs=1")429 .reference("command 1")430 .command("command 1")431 .command("command 2")413 .expect_output("command 1")414 .expect_output("command 1")415 .expect_output("command 2")432 .run();433434 insta::assert_snapshot!(output, @r"435 command 1436 command 1437 command 2438 ");439}440441#[test]442fn setup_prepare_reference_conclude_cleanup_combined() {421 ExecutionOrderTest::new()443 let output = ExecutionOrderTest::new()444 .arg("--warmup=1")445 .arg("--runs=2")446 .setup("setup")447 .prepare("prepare")
1 unmodified line
449 .command("command1")450 .command("command2")451 .conclude("conclude")452 .cleanup("cleanup")431 // reference432 .expect_output("setup")433 .expect_output("prepare")434 .expect_output("reference")435 .expect_output("conclude")436 .expect_output("prepare")437 .expect_output("reference")438 .expect_output("conclude")439 .expect_output("prepare")440 .expect_output("reference")441 .expect_output("conclude")442 .expect_output("cleanup")443 // 1444 .expect_output("setup")445 .expect_output("prepare")446 .expect_output("command1")447 .expect_output("conclude")448 .expect_output("prepare")449 .expect_output("command1")450 .expect_output("conclude")451 .expect_output("prepare")452 .expect_output("command1")453 .expect_output("conclude")454 .expect_output("cleanup")455 // 2456 .expect_output("setup")457 .expect_output("prepare")458 .expect_output("command2")459 .expect_output("conclude")460 .expect_output("prepare")461 .expect_output("command2")462 .expect_output("conclude")463 .expect_output("prepare")464 .expect_output("command2")465 .expect_output("conclude")466 .expect_output("cleanup")453 .run();454455 insta::assert_snapshot!(output, @r"456 setup457 prepare458 reference459 conclude460 prepare461 reference462 conclude463 prepare464 reference465 conclude466 cleanup467 setup468 prepare469 command1470 conclude471 prepare472 command1473 conclude474 prepare475 command1476 conclude477 cleanup478 setup479 prepare480 command2481 conclude482 prepare483 command2484 conclude485 prepare486 command2487 conclude488 cleanup489 ");490}491492#[test]493fn setup_separate_prepare_separate_conclude_cleanup_combined() {472 ExecutionOrderTest::new()494 let output = ExecutionOrderTest::new()495 .arg("--warmup=1")496 .arg("--runs=2")497 .setup("setup")498 .cleanup("cleanup")
2 unmodified lines
501 .conclude("conclude1")502 .prepare("prepare2")503 .command("command2")504 .conclude("conclude2")483 // 1484 .expect_output("setup")485 .expect_output("prepare1")486 .expect_output("command1")487 .expect_output("conclude1")488 .expect_output("prepare1")489 .expect_output("command1")490 .expect_output("conclude1")491 .expect_output("prepare1")492 .expect_output("command1")493 .expect_output("conclude1")494 .expect_output("cleanup")495 // 2496 .expect_output("setup")497 .expect_output("prepare2")498 .expect_output("command2")499 .expect_output("conclude2")500 .expect_output("prepare2")501 .expect_output("command2")502 .expect_output("conclude2")503 .expect_output("prepare2")504 .expect_output("command2")505 .expect_output("conclude2")506 .expect_output("cleanup")505 .run();506507 insta::assert_snapshot!(output, @r"508 setup509 prepare1510 command1511 conclude1512 prepare1513 command1514 conclude1515 prepare1516 command1517 conclude1518 cleanup519 setup520 prepare2521 command2522 conclude2523 prepare2524 command2525 conclude2526 prepare2527 command2528 conclude2529 cleanup530 ");531}532533#[test]534fn setup_separate_prepare_reference_separate_conclude_cleanup_combined() {512 ExecutionOrderTest::new()535 let output = ExecutionOrderTest::new()536 .arg("--warmup=1")537 .arg("--runs=2")538 .setup("setup")539 .cleanup("cleanup")
5 unmodified lines
545 .conclude("conclude1")546 .prepare("prepare2")547 .command("command2")548 .conclude("conclude2")526 // reference527 .expect_output("setup")528 .expect_output("prepareref")529 .expect_output("reference")530 .expect_output("concluderef")531 .expect_output("prepareref")532 .expect_output("reference")533 .expect_output("concluderef")534 .expect_output("prepareref")535 .expect_output("reference")536 .expect_output("concluderef")537 .expect_output("cleanup")538 // 1539 .expect_output("setup")540 .expect_output("prepare1")541 .expect_output("command1")542 .expect_output("conclude1")543 .expect_output("prepare1")544 .expect_output("command1")545 .expect_output("conclude1")546 .expect_output("prepare1")547 .expect_output("command1")548 .expect_output("conclude1")549 .expect_output("cleanup")550 // 2551 .expect_output("setup")552 .expect_output("prepare2")553 .expect_output("command2")554 .expect_output("conclude2")555 .expect_output("prepare2")556 .expect_output("command2")557 .expect_output("conclude2")558 .expect_output("prepare2")559 .expect_output("command2")560 .expect_output("conclude2")561 .expect_output("cleanup")549 .run();550551 insta::assert_snapshot!(output, @r"552 setup553 prepareref554 reference555 concluderef556 prepareref557 reference558 concluderef559 prepareref560 reference561 concluderef562 cleanup563 setup564 prepare1565 command1566 conclude1567 prepare1568 command1569 conclude1570 prepare1571 command1572 conclude1573 cleanup574 setup575 prepare2576 command2577 conclude2578 prepare2579 command2580 conclude2581 prepare2582 command2583 conclude2584 cleanup585 ");586}
modified:tests/integration_tests.rs+213 added-62 removed
13 unmodified lines
14 cmd.arg("--debug-mode");15 cmd16}1718// Ignore trailing padding on report lines, including the space-only separators.19// Keep indentation and internal spacing so snapshots still check the layout.20fn stdout(output: &assert_cmd::assert::Assert) -> String {21 String::from_utf8_lossy(&output.get_output().stdout)22 .lines()23 .map(str::trim_end)24 .collect::<Vec<_>>()25 .join("\n")26}2728#[test]29fn runs_successfully() {30 hyperfine()31 .arg("--runs=2")
571 unmodified lines
603}604605#[test]606fn shows_benchmark_comparison_with_relative_times() {597 hyperfine_debug()607 let output = hyperfine_debug()608 .arg("--style=basic")609 .arg("sleep 1.0")610 .arg("sleep 2.0")611 .arg("sleep 3.0")612 .assert()602 .success()603 .stdout(604 predicate::str::contains("2.00 ± 0.00 times faster")605 .and(predicate::str::contains("3.00 ± 0.00 times faster")),606 );613 .success();614615 insta::assert_snapshot!(stdout(&output), @r"616 Benchmark 1: sleep 1.0617 Time (mean ± σ): 1.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]618 Range (min … max): 1.000 s … 1.000 s 10 runs619620 Benchmark 2: sleep 2.0621 Time (mean ± σ): 2.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]622 Range (min … max): 2.000 s … 2.000 s 10 runs623624 Benchmark 3: sleep 3.0625 Time (mean ± σ): 3.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]626 Range (min … max): 3.000 s … 3.000 s 10 runs627628 Summary629 sleep 1.0 ran630 2.00 ± 0.00 times faster than sleep 2.0631 3.00 ± 0.00 times faster than sleep 3.0632 ");633}634635#[test]636fn shows_benchmark_comparison_with_same_time() {611 hyperfine_debug()637 let output = hyperfine_debug()638 .arg("--style=basic")639 .arg("--command-name=A")640 .arg("--command-name=B")641 .arg("sleep 1.0")642 .arg("sleep 1.0")643 .arg("sleep 2.0")644 .arg("sleep 1000.0")645 .assert()619 .success()620 .stdout(621 predicate::str::contains("As fast (1.00 ± 0.00) as")622 .and(predicate::str::contains("2.00 ± 0.00 times faster"))623 .and(predicate::str::contains("1000.00 ± 0.00 times faster")),624 );646 .success();647648 insta::assert_snapshot!(stdout(&output), @r"649 Benchmark 1: A650 Time (mean ± σ): 1.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]651 Range (min … max): 1.000 s … 1.000 s 10 runs652653 Benchmark 2: B654 Time (mean ± σ): 1.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]655 Range (min … max): 1.000 s … 1.000 s 10 runs656657 Benchmark 3: sleep 2.0658 Time (mean ± σ): 2.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]659 Range (min … max): 2.000 s … 2.000 s 10 runs660661 Benchmark 4: sleep 1000.0662 Time (mean ± σ): 1000.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]663 Range (min … max): 1000.000 s … 1000.000 s 10 runs664665 Summary666 A ran667 As fast (1.00 ± 0.00) as B668 2.00 ± 0.00 times faster than sleep 2.0669 1000.00 ± 0.00 times faster than sleep 1000.0670 ");671}672673#[test]674fn shows_benchmark_comparison_relative_to_reference() {629 hyperfine_debug()675 let output = hyperfine_debug()676 .arg("--style=basic")677 .arg("--reference=sleep 2.0")678 .arg("sleep 1.0")679 .arg("sleep 3.0")680 .assert()634 .success()635 .stdout(636 predicate::str::contains("2.00 ± 0.00 times slower")637 .and(predicate::str::contains("1.50 ± 0.00 times faster")),638 );681 .success();682683 insta::assert_snapshot!(stdout(&output), @r"684 Benchmark 1: sleep 2.0685 Time (mean ± σ): 2.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]686 Range (min … max): 2.000 s … 2.000 s 10 runs687688 Benchmark 2: sleep 1.0689 Time (mean ± σ): 1.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]690 Range (min … max): 1.000 s … 1.000 s 10 runs691692 Benchmark 3: sleep 3.0693 Time (mean ± σ): 3.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]694 Range (min … max): 3.000 s … 3.000 s 10 runs695696 Summary697 sleep 2.0 ran698 2.00 ± 0.00 times slower than sleep 1.0699 1.50 ± 0.00 times faster than sleep 3.0700 ");701}702703#[test]704fn shows_reference_name() {643 hyperfine_debug()705 let output = hyperfine_debug()706 .arg("--style=basic")707 .arg("--reference=sleep 2.0")708 .arg("--reference-name=refabc123")709 .arg("sleep 1.0")710 .arg("sleep 3.0")711 .assert()649 .success()650 .stdout(predicate::str::contains("Benchmark 1: refabc123"));712 .success();713714 insta::assert_snapshot!(stdout(&output), @r"715 Benchmark 1: refabc123716 Time (mean ± σ): 2.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]717 Range (min … max): 2.000 s … 2.000 s 10 runs718719 Benchmark 2: sleep 1.0720 Time (mean ± σ): 1.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]721 Range (min … max): 1.000 s … 1.000 s 10 runs722723 Benchmark 3: sleep 3.0724 Time (mean ± σ): 3.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]725 Range (min … max): 3.000 s … 3.000 s 10 runs726727 Summary728 refabc123 ran729 2.00 ± 0.00 times slower than sleep 1.0730 1.50 ± 0.00 times faster than sleep 3.0731 ");732}733734#[test]735fn performs_all_benchmarks_in_parameter_scan() {655 hyperfine_debug()736 let output = hyperfine_debug()737 .arg("--style=basic")738 .arg("--parameter-scan")739 .arg("time")740 .arg("30")741 .arg("45")742 .arg("--parameter-step-size")743 .arg("5")744 .arg("sleep {time}")745 .assert()664 .success()665 .stdout(666 predicate::str::contains("Benchmark 1: sleep 30")667 .and(predicate::str::contains("Benchmark 2: sleep 35"))668 .and(predicate::str::contains("Benchmark 3: sleep 40"))669 .and(predicate::str::contains("Benchmark 4: sleep 45"))670 .and(predicate::str::contains("Benchmark 5: sleep 50").not()),671 );746 .success();747748 insta::assert_snapshot!(stdout(&output), @r"749 Benchmark 1: sleep 30750 Time (mean ± σ): 30.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]751 Range (min … max): 30.000 s … 30.000 s 10 runs752753 Benchmark 2: sleep 35754 Time (mean ± σ): 35.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]755 Range (min … max): 35.000 s … 35.000 s 10 runs756757 Benchmark 3: sleep 40758 Time (mean ± σ): 40.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]759 Range (min … max): 40.000 s … 40.000 s 10 runs760761 Benchmark 4: sleep 45762 Time (mean ± σ): 45.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]763 Range (min … max): 45.000 s … 45.000 s 10 runs764765 Summary766 sleep 30 ran767 1.17 ± 0.00 times faster than sleep 35768 1.33 ± 0.00 times faster than sleep 40769 1.50 ± 0.00 times faster than sleep 45770 ");771}772773#[test]774fn performs_reference_and_all_benchmarks_in_parameter_scan() {676 hyperfine_debug()775 let output = hyperfine_debug()776 .arg("--style=basic")777 .arg("--reference=sleep 25")778 .arg("--parameter-scan")779 .arg("time")780 .arg("30")
1 unmodified line
782 .arg("--parameter-step-size")783 .arg("5")784 .arg("sleep {time}")785 .assert()686 .success()687 .stdout(688 predicate::str::contains("Benchmark 1: sleep 25")689 .and(predicate::str::contains("Benchmark 2: sleep 30"))690 .and(predicate::str::contains("Benchmark 3: sleep 35"))691 .and(predicate::str::contains("Benchmark 4: sleep 40"))692 .and(predicate::str::contains("Benchmark 5: sleep 45"))693 .and(predicate::str::contains("Benchmark 6: sleep 50").not()),694 );786 .success();787788 insta::assert_snapshot!(stdout(&output), @r"789 Benchmark 1: sleep 25790 Time (mean ± σ): 25.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]791 Range (min … max): 25.000 s … 25.000 s 10 runs792793 Benchmark 2: sleep 30794 Time (mean ± σ): 30.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]795 Range (min … max): 30.000 s … 30.000 s 10 runs796797 Benchmark 3: sleep 35798 Time (mean ± σ): 35.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]799 Range (min … max): 35.000 s … 35.000 s 10 runs800801 Benchmark 4: sleep 40802 Time (mean ± σ): 40.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]803 Range (min … max): 40.000 s … 40.000 s 10 runs804805 Benchmark 5: sleep 45806 Time (mean ± σ): 45.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]807 Range (min … max): 45.000 s … 45.000 s 10 runs808809 Summary810 sleep 25 ran811 1.20 ± 0.00 times faster than sleep 30812 1.40 ± 0.00 times faster than sleep 35813 1.60 ± 0.00 times faster than sleep 40814 1.80 ± 0.00 times faster than sleep 45815 ");816}817818#[test]819fn intermediate_results_are_not_exported_to_stdout() {699 hyperfine_debug()820 let output = hyperfine_debug()821 .arg("--style=none") // To only see the Markdown export on stdout822 .arg("--export-markdown")823 .arg("-")824 .arg("sleep 1")825 .arg("sleep 2")826 .assert()706 .success()707 .stdout(708 (predicate::str::contains("sleep 1").count(1))709 .and(predicate::str::contains("sleep 2").count(1)),710 );827 .success();828829 insta::assert_snapshot!(stdout(&output), @r"830831 | Command | Mean [s] | Min [s] | Max [s] | Relative |832 |:---|---:|---:|---:|---:|833 | `sleep 1` | 1.000 ± 0.000 | 1.000 | 1.000 | 1.00 |834 | `sleep 2` | 2.000 ± 0.000 | 2.000 | 2.000 | 2.00 ± 0.00 |835 ");836}837838#[test]839#[cfg(unix)]
33 unmodified lines
873}874875#[test]876fn speed_comparison_sort_order() {752 for sort_order in ["auto", "mean-time"] {753 hyperfine_debug()754 .arg("sleep 2")755 .arg("sleep 1")756 .arg(format!("--sort={sort_order}"))757 .assert()758 .success()759 .stdout(predicate::str::contains(760 "sleep 1 ran\n 2.00 ± 0.00 times faster than sleep 2",761 ));877 insta::allow_duplicates! {878 for sort_order in ["auto", "mean-time"] {879 let output = hyperfine_debug()880 .arg("--style=basic")881 .arg("sleep 2")882 .arg("sleep 1")883 .arg(format!("--sort={sort_order}"))884 .assert()885 .success();886887 insta::assert_snapshot!(stdout(&output), @r"888 Benchmark 1: sleep 2889 Time (mean ± σ): 2.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]890 Range (min … max): 2.000 s … 2.000 s 10 runs891892 Benchmark 2: sleep 1893 Time (mean ± σ): 1.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]894 Range (min … max): 1.000 s … 1.000 s 10 runs895896 Summary897 sleep 1 ran898 2.00 ± 0.00 times faster than sleep 2899 ");900 }901 }902764 hyperfine_debug()903 let output = hyperfine_debug()904 .arg("--style=basic")905 .arg("sleep 2")906 .arg("sleep 1")907 .arg("--sort=command")908 .assert()769 .success()770 .stdout(predicate::str::contains(771 "2.00 ± 0.00 sleep 2\n 1.00 sleep 1",772 ));909 .success();910911 insta::assert_snapshot!(stdout(&output), @r"912 Benchmark 1: sleep 2913 Time (mean ± σ): 2.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]914 Range (min … max): 2.000 s … 2.000 s 10 runs915916 Benchmark 2: sleep 1917 Time (mean ± σ): 1.000 s ± 0.000 s [User: 0.000 s, System: 0.000 s]918 Range (min … max): 1.000 s … 1.000 s 10 runs919920 Relative speed comparison921 2.00 ± 0.00 sleep 2922 1.00 sleep 1923 ");924}925926#[cfg(windows)]927#[test]
15 unmodified lines