Skip to content
Myr

Keep snapshot conversions limited to integration tests

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 1e2e0be · Browse files · 1 file+281 added−304 removed
This commit

State

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

Diff stats

1 file+281 added−304 removed

  • tests:+281 added−304 removed

1 file+281 added−304 removed

modified:tests/execution_order_tests.rs+281 added-304 removed
1use std::{fs, path::PathBuf};1use std::{fs::File, io::Read, path::PathBuf};23use tempfile::{tempdir, TempDir};45mod common;6use common::hyperfine;78struct ExecutionOrderTest {9 cmd: assert_cmd::Command,10 expected_content: String,11 logfile_path: PathBuf,12 #[allow(dead_code)]13 tempdir: TempDir,14}
4 unmodified lines
19 let logfile_path = tempdir.path().join("output.log");2021 ExecutionOrderTest {22 cmd: hyperfine(),23 expected_content: String::new(),24 logfile_path,25 tempdir,26 }27 }
40 unmodified lines
68 self.arg("--cleanup");69 self.command(output)70 }7170 fn run(&mut self) -> String {71 self.cmd.assert().success();72 fn expect_output(&mut self, output: &str) -> &mut Self {73 self.expected_content.push_str(output);7473 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 let content = content.replace(" \r\n", "\n");77 content76 {77 self.expected_content.push_str(" \r");78 }7980 self.expected_content.push('\n');81 self82 }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 }93}9495impl Default for ExecutionOrderTest {96 fn default() -> Self {
2 unmodified lines
99}100101#[test]102fn benchmarks_are_executed_sequentially_one() {89 let output = ExecutionOrderTest::new()103 ExecutionOrderTest::new()104 .arg("--runs=1")105 .command("command 1")106 .command("command 2")107 .expect_output("command 1")108 .expect_output("command 2")109 .run();9495 insta::assert_snapshot!(output, @r"96 command 197 command 298 ");110}111112#[test]113fn benchmarks_are_executed_sequentially() {103 let output = ExecutionOrderTest::new()114 ExecutionOrderTest::new()115 .arg("--runs=2")116 .command("command 1")117 .command("command 2")118 .expect_output("command 1")119 .expect_output("command 1")120 .expect_output("command 2")121 .expect_output("command 2")122 .run();108109 insta::assert_snapshot!(output, @r"110 command 1111 command 1112 command 2113 command 2114 ");123}124125#[test]126fn warmup_runs_are_executed_before_benchmarking_runs() {119 let output = ExecutionOrderTest::new()127 ExecutionOrderTest::new()128 .arg("--runs=2")129 .arg("--warmup=3")130 .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")136 .run();124125 insta::assert_snapshot!(output, @r"126 command 1127 command 1128 command 1129 command 1130 command 1131 ");137}138139#[test]140fn setup_commands_are_executed_before_each_series_of_timing_runs() {136 let output = ExecutionOrderTest::new()141 ExecutionOrderTest::new()142 .arg("--runs=2")143 .setup("setup")144 .command("command 1")145 .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")152 .run();142143 insta::assert_snapshot!(output, @r"144 setup145 command 1146 command 1147 setup148 command 2149 command 2150 ");153}154155#[test]156fn prepare_commands_are_executed_before_each_timing_run() {155 let output = ExecutionOrderTest::new()157 ExecutionOrderTest::new()158 .arg("--runs=2")159 .prepare("prepare")160 .command("command 1")161 .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")170 .run();161162 insta::assert_snapshot!(output, @r"163 prepare164 command 1165 prepare166 command 1167 prepare168 command 2169 prepare170 command 2171 ");171}172173#[test]174fn conclude_commands_are_executed_after_each_timing_run() {176 let output = ExecutionOrderTest::new()175 ExecutionOrderTest::new()176 .arg("--runs=2")177 .conclude("conclude")178 .command("command 1")179 .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")188 .run();182183 insta::assert_snapshot!(output, @r"184 command 1185 conclude186 command 1187 conclude188 command 2189 conclude190 command 2191 conclude192 ");189}190191#[test]192fn prepare_commands_are_executed_before_each_warmup() {197 let output = ExecutionOrderTest::new()193 ExecutionOrderTest::new()194 .arg("--warmup=2")195 .arg("--runs=1")196 .prepare("prepare")197 .command("command 1")198 .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")215 .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 ");216}217218#[test]219fn conclude_commands_are_executed_after_each_warmup() {223 let output = ExecutionOrderTest::new()220 ExecutionOrderTest::new()221 .arg("--warmup=2")222 .arg("--runs=1")223 .conclude("conclude")224 .command("command 1")225 .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")242 .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 ");243}244245#[test]246fn cleanup_commands_are_executed_once_after_each_benchmark() {249 let output = ExecutionOrderTest::new()247 ExecutionOrderTest::new()248 .arg("--runs=2")249 .cleanup("cleanup")250 .command("command 1")251 .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")258 .run();255256 insta::assert_snapshot!(output, @r"257 command 1258 command 1259 cleanup260 command 2261 command 2262 cleanup263 ");259}260261#[test]262fn setup_prepare_cleanup_combined() {268 let output = ExecutionOrderTest::new()263 ExecutionOrderTest::new()264 .arg("--warmup=1")265 .arg("--runs=2")266 .setup("setup")267 .prepare("prepare")268 .command("command1")269 .command("command2")270 .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")289 .run();277278 insta::assert_snapshot!(output, @r"279 setup280 prepare281 command1282 prepare283 command1284 prepare285 command1286 cleanup287 setup288 prepare289 command2290 prepare291 command2292 prepare293 command2294 cleanup295 ");290}291292#[test]293fn setup_prepare_conclude_cleanup_combined() {300 let output = ExecutionOrderTest::new()294 ExecutionOrderTest::new()295 .arg("--warmup=1")296 .arg("--runs=2")297 .setup("setup")298 .prepare("prepare")299 .command("command1")300 .command("command2")301 .conclude("conclude")302 .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")327 .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 ");328}329330#[test]331fn single_parameter_value() {339 let output = ExecutionOrderTest::new()332 ExecutionOrderTest::new()333 .arg("--runs=2")334 .arg("--parameter-list")335 .arg("number")336 .arg("1,2,3")337 .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")344 .run();346347 insta::assert_snapshot!(output, @r"348 command 1349 command 1350 command 2351 command 2352 command 3353 command 3354 ");345}346347#[test]348fn multiple_parameter_values() {359 let output = ExecutionOrderTest::new()349 ExecutionOrderTest::new()350 .arg("--runs=2")351 .arg("--parameter-list")352 .arg("number")353 .arg("1,2,3")354 .arg("--parameter-list")355 .arg("letter")356 .arg("a,b")357 .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")370 .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 ");371}372373#[test]374fn reference_is_executed_first() {388 let output = ExecutionOrderTest::new()375 ExecutionOrderTest::new()376 .arg("--runs=1")377 .reference("reference")378 .command("command 1")379 .command("command 2")380 .expect_output("reference")381 .expect_output("command 1")382 .expect_output("command 2")383 .run();394395 insta::assert_snapshot!(output, @r"396 reference397 command 1398 command 2399 ");384}385386#[test]387fn reference_is_executed_first_parameter_value() {404 let output = ExecutionOrderTest::new()388 ExecutionOrderTest::new()389 .arg("--runs=2")390 .reference("reference")391 .arg("--parameter-list")392 .arg("number")393 .arg("1,2,3")394 .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")403 .run();412413 insta::assert_snapshot!(output, @r"414 reference415 reference416 command 1417 command 1418 command 2419 command 2420 command 3421 command 3422 ");404}405406#[test]407fn reference_is_executed_separately_from_commands() {427 let output = ExecutionOrderTest::new()408 ExecutionOrderTest::new()409 .arg("--runs=1")410 .reference("command 1")411 .command("command 1")412 .command("command 2")413 .expect_output("command 1")414 .expect_output("command 1")415 .expect_output("command 2")416 .run();433434 insta::assert_snapshot!(output, @r"435 command 1436 command 1437 command 2438 ");417}418419#[test]420fn setup_prepare_reference_conclude_cleanup_combined() {443 let output = ExecutionOrderTest::new()421 ExecutionOrderTest::new()422 .arg("--warmup=1")423 .arg("--runs=2")424 .setup("setup")425 .prepare("prepare")
1 unmodified line
427 .command("command1")428 .command("command2")429 .conclude("conclude")430 .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")467 .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 ");468}469470#[test]471fn setup_separate_prepare_separate_conclude_cleanup_combined() {494 let output = ExecutionOrderTest::new()472 ExecutionOrderTest::new()473 .arg("--warmup=1")474 .arg("--runs=2")475 .setup("setup")476 .cleanup("cleanup")
2 unmodified lines
479 .conclude("conclude1")480 .prepare("prepare2")481 .command("command2")482 .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")507 .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 ");508}509510#[test]511fn setup_separate_prepare_reference_separate_conclude_cleanup_combined() {535 let output = ExecutionOrderTest::new()512 ExecutionOrderTest::new()513 .arg("--warmup=1")514 .arg("--runs=2")515 .setup("setup")516 .cleanup("cleanup")
5 unmodified lines
522 .conclude("conclude1")523 .prepare("prepare2")524 .command("command2")525 .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")562 .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 ");563}