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

Preserve export files when command options are invalid
This commit is contained in:
David Peter authored and GitHub committed 2026-10-05 11:30:58 +02:00
commit d3d67fc908
2 files changed
+45 -2

No files matched your search

+2 -2
View File
@@ -37,14 +37,14 @@ fn run() -> Result<()> {
let cli_arguments = get_cli_arguments(env::args_os());
let mut options = Options::from_cli_arguments(&cli_arguments)?;
let commands = Commands::from_cli_arguments(&cli_arguments)?;
options.validate_against_command_list(&commands)?;
let export_manager = ExportManager::from_cli_arguments(
&cli_arguments,
options.time_unit,
options.sort_order_exports,
)?;
options.validate_against_command_list(&commands)?;
let mut scheduler = Scheduler::new(&commands, &options, &export_manager);
scheduler.run_benchmarks()?;
scheduler.print_relative_speed_comparison()?;
+43
View File
@@ -870,6 +870,49 @@ fn exports_intermediate_results_to_file() {
assert!(contents.contains("true"));
}
#[test]
fn invalid_command_options_preserve_export_files() {
use tempfile::tempdir;
for (option, values) in [
("--prepare", ["echo first", "echo second"]),
("--conclude", ["echo first", "echo second"]),
("--output", ["null", "pipe"]),
] {
let directory = tempdir().unwrap();
let existing_export = directory.path().join("previous.json");
let new_export = directory.path().join("new.csv");
let previous_results =
b"{\"results\":[{\"command\":\"previous benchmark\",\"mean\":1.0}]}\n";
std::fs::write(&existing_export, previous_results).unwrap();
hyperfine()
.arg("--runs=1")
.arg("--export-json")
.arg(&existing_export)
.arg("--export-csv")
.arg(&new_export)
.args([option, values[0], option, values[1]])
.arg("echo benchmark")
.assert()
.failure()
.stderr(predicate::str::contains(format!(
"The '{option}' option has to be provided just once or N times"
)));
assert_eq!(
std::fs::read(&existing_export).unwrap(),
previous_results,
"{option} validation must preserve previous results"
);
assert!(
!new_export.exists(),
"{} validation must not create export files",
option
);
}
}
#[test]
fn unused_parameters_are_shown_in_benchmark_name() {
hyperfine()