Skip to content
Myr

Merge pull request #950 from Likio3000/codex/preserve-exports-on-invalid-options

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

Preserve export files when command options are invalid

authored by David Peter · committed by GitHub · parents e43bf85, e2717c0 · 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
35 unmodified lines
3637 let cli_arguments = get_cli_arguments(env::args_os());38 let mut options = Options::from_cli_arguments(&cli_arguments)?;39 let commands = Commands::from_cli_arguments(&cli_arguments)?;40 options.validate_against_command_list(&commands)?;4142 let export_manager = ExportManager::from_cli_arguments(43 &cli_arguments,44 options.time_unit,45 options.sort_order_exports,46 )?;4746 options.validate_against_command_list(&commands)?;4748 let mut scheduler = Scheduler::new(&commands, &options, &export_manager);49 scheduler.run_benchmarks()?;50 scheduler.print_relative_speed_comparison()?;51 scheduler.final_export()?;
25 unmodified lines
modified:tests/integration_tests.rs+43 added
869 unmodified lines
870 assert!(contents.contains("true"));871}872873#[test]874fn invalid_command_options_preserve_export_files() {875 use tempfile::tempdir;876877 for (option, values) in [878 ("--prepare", ["echo first", "echo second"]),879 ("--conclude", ["echo first", "echo second"]),880 ("--output", ["null", "pipe"]),881 ] {882 let directory = tempdir().unwrap();883 let existing_export = directory.path().join("previous.json");884 let new_export = directory.path().join("new.csv");885 let previous_results =886 b"{\"results\":[{\"command\":\"previous benchmark\",\"mean\":1.0}]}\n";887 std::fs::write(&existing_export, previous_results).unwrap();888889 hyperfine()890 .arg("--runs=1")891 .arg("--export-json")892 .arg(&existing_export)893 .arg("--export-csv")894 .arg(&new_export)895 .args([option, values[0], option, values[1]])896 .arg("echo benchmark")897 .assert()898 .failure()899 .stderr(predicate::str::contains(format!(900 "The '{option}' option has to be provided just once or N times"901 )));902903 assert_eq!(904 std::fs::read(&existing_export).unwrap(),905 previous_results,906 "{option} validation must preserve previous results"907 );908 assert!(909 !new_export.exists(),910 "{} validation must not create export files",911 option912 );913 }914}915916#[test]917fn unused_parameters_are_shown_in_benchmark_name() {918 hyperfine()919 .arg("--runs=2")920 .arg("--parameter-list")
82 unmodified lines