Skip to content
Myr

Preserve export files when command options are invalid

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

authored by Eric Soler · committed by Eric Soler · parent 0f7ae35 · Browse files · 2 files+45 added−2 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+45 added−2 removed

  • tests:+43 added−0 removed
  • other:+2 added−2 removed

2 files+45 added−2 removed

modified:src/main.rs+2 added-2 removed
34 unmodified lines
3536 let cli_arguments = get_cli_arguments(env::args_os());37 let mut options = Options::from_cli_arguments(&cli_arguments)?;38 let commands = Commands::from_cli_arguments(&cli_arguments)?;39 options.validate_against_command_list(&commands)?;4041 let export_manager = ExportManager::from_cli_arguments(42 &cli_arguments,43 options.time_unit,44 options.sort_order_exports,45 )?;4645 options.validate_against_command_list(&commands)?;4647 let mut scheduler = Scheduler::new(&commands, &options, &export_manager);48 scheduler.run_benchmarks()?;49 scheduler.print_relative_speed_comparison()?;50 scheduler.final_export()?;
25 unmodified lines
modified:tests/integration_tests.rs+43 added
730 unmodified lines
731 assert!(contents.contains("true"));732}733734#[test]735fn invalid_command_options_preserve_export_files() {736 use tempfile::tempdir;737738 for (option, values) in [739 ("--prepare", ["echo first", "echo second"]),740 ("--conclude", ["echo first", "echo second"]),741 ("--output", ["null", "pipe"]),742 ] {743 let directory = tempdir().unwrap();744 let existing_export = directory.path().join("previous.json");745 let new_export = directory.path().join("new.csv");746 let previous_results =747 b"{\"results\":[{\"command\":\"previous benchmark\",\"mean\":1.0}]}\n";748 std::fs::write(&existing_export, previous_results).unwrap();749750 hyperfine()751 .arg("--runs=1")752 .arg("--export-json")753 .arg(&existing_export)754 .arg("--export-csv")755 .arg(&new_export)756 .args([option, values[0], option, values[1]])757 .arg("echo benchmark")758 .assert()759 .failure()760 .stderr(predicate::str::contains(format!(761 "The '{option}' option has to be provided just once or N times"762 )));763764 assert_eq!(765 std::fs::read(&existing_export).unwrap(),766 previous_results,767 "{option} validation must preserve previous results"768 );769 assert!(770 !new_export.exists(),771 "{} validation must not create export files",772 option773 );774 }775}776777#[test]778fn unused_parameters_are_shown_in_benchmark_name() {779 hyperfine()780 .arg("--runs=2")781 .arg("--parameter-list")
53 unmodified lines