Fixed bug on naming individual commands with parameter scan
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Teodoro Freund · committed by David Peter · parent 5e32684 · Browse files · 1 file·+45 added−10 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+45 added−10 removed
- other:+45 added−10 removed
Provenance
- Commit
835fc43- Tree
f7a3cdf- Author
Teodoro Freund <tfreund95@gmail.com>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
5e32684
1 file changed+45 added−10 removed
modified:src/command.rs+45 added-10 removed
275 unmodified lines276 command_names: Vec<&'b str>,277 command_strings: Vec<&'b str>,278 ) -> Result<Vec<Command<'b>>, ParameterScanError> {279 let param_range = RangeStep::new(param_min, param_max, step)?;280- let param_count = param_range.size_hint().1.unwrap();280 let command_name_count = command_names.len();281 283- // `--command-name` should appear exactly once or exactly B times,284- // where B is the total number of benchmarks.285- if command_name_count > 1 && command_name_count != param_count {286- return Err(ParameterScanError::UnexpectedCommandNameCount(287- command_name_count,288- param_count,289- ));290- }291-282 let mut i = 0;283 let mut commands = vec![];284 for value in param_range {285 for cmd in &command_strings {8 unmodified lines294 ));295 i += 1;296 }297 }298+299+ // `--command-name` should appear exactly once or exactly B times,300+ // where B is the total number of benchmarks.301+ let command_count = commands.len();302+ if command_name_count > 1 && command_name_count != command_count {303+ return Err(ParameterScanError::UnexpectedCommandNameCount(304+ command_name_count,305+ command_count,306+ ));307+ }308+309 Ok(commands)310 }311 312 fn get_parameter_scan_commands<'b>(159 unmodified lines472 assert_eq!(commands[1].get_command_line(), "echo 2");473 }474 475 #[test]476+fn test_build_parameter_scan_commands_named() {477+ use crate::cli::get_cli_arguments;478+ let matches = get_cli_arguments(vec![479+ "hyperfine",480+ "echo {val}",481+ "sleep {val}",482+ "--parameter-scan",483+ "val",484+ "1",485+ "2",486+ "--parameter-step-size",487+ "1",488+ "--command-name",489+ "echo-1",490+ "--command-name",491+ "sleep-1",492+ "--command-name",493+ "echo-2",494+ "--command-name",495+ "sleep-2",496+ ]);497+ let commands = Commands::from_cli_arguments(&matches).unwrap().0;498+ assert_eq!(commands.len(), 4);499+ assert_eq!(commands[0].get_name(), "echo-1");500+ assert_eq!(commands[0].get_command_line(), "echo 1");501+ assert_eq!(commands[1].get_name(), "sleep-1");502+ assert_eq!(commands[1].get_command_line(), "sleep 1");503+ assert_eq!(commands[2].get_name(), "echo-2");504+ assert_eq!(commands[2].get_command_line(), "echo 2");505+ assert_eq!(commands[3].get_name(), "sleep-2");506+ assert_eq!(commands[3].get_command_line(), "sleep 2");507+}508+509+#[test]510 fn test_parameter_scan_commands_int() {511 let commands = Commands::build_parameter_scan_commands(512 "val",513 1i32,84 unmodified lines