mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-03 01:21:25 +00:00
Preserve export files when command options are invalid
This commit is contained in:
1 parent
0f7ae35626
commit
e2717c064e
2 files changed
+45
-2
No files matched your search
+2
-2
@@ -36,14 +36,14 @@ fn run() -> Result<()> {
|
|||||||
let cli_arguments = get_cli_arguments(env::args_os());
|
let cli_arguments = get_cli_arguments(env::args_os());
|
||||||
let mut options = Options::from_cli_arguments(&cli_arguments)?;
|
let mut options = Options::from_cli_arguments(&cli_arguments)?;
|
||||||
let commands = Commands::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(
|
let export_manager = ExportManager::from_cli_arguments(
|
||||||
&cli_arguments,
|
&cli_arguments,
|
||||||
options.time_unit,
|
options.time_unit,
|
||||||
options.sort_order_exports,
|
options.sort_order_exports,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
options.validate_against_command_list(&commands)?;
|
|
||||||
|
|
||||||
let mut scheduler = Scheduler::new(&commands, &options, &export_manager);
|
let mut scheduler = Scheduler::new(&commands, &options, &export_manager);
|
||||||
scheduler.run_benchmarks()?;
|
scheduler.run_benchmarks()?;
|
||||||
scheduler.print_relative_speed_comparison()?;
|
scheduler.print_relative_speed_comparison()?;
|
||||||
|
|||||||
@@ -731,6 +731,49 @@ fn exports_intermediate_results_to_file() {
|
|||||||
assert!(contents.contains("true"));
|
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]
|
#[test]
|
||||||
fn unused_parameters_are_shown_in_benchmark_name() {
|
fn unused_parameters_are_shown_in_benchmark_name() {
|
||||||
hyperfine()
|
hyperfine()
|
||||||
|
|||||||
Reference in new issue
Block a user