command.rs
This file
Path
src/command.rs
537 lines · 16.7 KiB · Rust
Last changed by
Use raw executor by default, skip intermediate shellDavid Peterbefore adoptiond9418e0
History of this fileTake it
Flat directory/module structureDavid Peterbefore adoption30c381f
lines 1–2why, one step back1use std::collections::BTreeMap;2use std::fmt;Split range into range_step and commandsDavid Peterbefore adoption6db82cd
line 3why, one step back3use std::str::FromStr;Flat directory/module structureDavid Peterbefore adoption30c381f
line 4why, one step back4Split range into range_step and commandsDavid Peterbefore adoption6db82cd
lines 5–6why, one step back5use crate::{6 error::{OptionsError, ParameterScanError},Move functions into SchedulerDavid Peterbefore adoption39c7736
lines 7–10why, one step back7 parameter::{8 range_step::{Numeric, RangeStep},9 ParameterNameAndValue,10 },Split range into range_step and commandsDavid Peterbefore adoption6db82cd
line 11why, one step back11};Move build_commandsDavid Peterbefore adoptioncd38e9c
lines 12–14why, one step back1213use clap::ArgMatches;14New parameter moduleDavid Peterbefore adoption47091a5
lines 15–16why, one step back15use crate::parameter::tokenize::tokenize;16use crate::parameter::ParameterValue;Flat directory/module structureDavid Peterbefore adoption30c381f
line 17why, one step back17Use raw executor by default, skip intermediate shellDavid Peterbefore adoptiond9418e0
line 18why, one step back18use anyhow::{bail, Context, Result};Split range into range_step and commandsDavid Peterbefore adoption6db82cd
lines 19–20why, one step back19use clap::Values;20use rust_decimal::Decimal;Move build_commandsDavid Peterbefore adoptioncd38e9c
line 21why, one step back21Flat directory/module structureDavid Peterbefore adoption30c381f
lines 22–31why, one step back22/// A command that should be benchmarked.23#[derive(Debug, Clone, PartialEq, Eq)]24pub struct Command<'a> {25 /// The command name (without parameter substitution)26 name: Option<&'a str>,2728 /// The command that should be executed (without parameter substitution)29 expression: &'a str,3031 /// Zero or more parameter values.Move functions into SchedulerDavid Peterbefore adoption39c7736
line 32why, one step back32 parameters: Vec<ParameterNameAndValue<'a>>,Flat directory/module structureDavid Peterbefore adoption30c381f
lines 33–46why, one step back33}3435impl<'a> Command<'a> {36 pub fn new(name: Option<&'a str>, expression: &'a str) -> Command<'a> {37 Command {38 name,39 expression,40 parameters: Vec::new(),41 }42 }4344 pub fn new_parametrized(45 name: Option<&'a str>,46 expression: &'a str,Move functions into SchedulerDavid Peterbefore adoption39c7736
line 47why, one step back47 parameters: impl IntoIterator<Item = ParameterNameAndValue<'a>>,Flat directory/module structureDavid Peterbefore adoption30c381f
lines 48–51why, one step back48 ) -> Command<'a> {49 Command {50 name,51 expression,Move functions into SchedulerDavid Peterbefore adoption39c7736
line 52why, one step back52 parameters: parameters.into_iter().collect(),Flat directory/module structureDavid Peterbefore adoption30c381f
lines 53–57why, one step back53 }54 }5556 pub fn get_name(&self) -> String {57 self.name.map_or_else(Rename to get_command_lineDavid Peterbefore adoption826449b
line 58why, one step back58 || self.get_command_line(),Flat directory/module structureDavid Peterbefore adoption30c381f
lines 59–62why, one step back59 |name| self.replace_parameters_in(name),60 )61 }62Rename to get_command_lineDavid Peterbefore adoption826449b
line 63why, one step back63 pub fn get_command_line(&self) -> String {Flat directory/module structureDavid Peterbefore adoption30c381f
line 64why, one step back64 self.replace_parameters_in(self.expression)Use raw executor by default, skip intermediate shellDavid Peterbefore adoptiond9418e0
lines 65–79why, one step back65 }6667 pub fn get_command(&self) -> Result<std::process::Command> {68 let command_line = self.get_command_line();69 let mut tokens = shell_words::split(&command_line)70 .with_context(|| format!("Failed to parse command '{}'", command_line))?71 .into_iter();7273 if let Some(program_name) = tokens.next() {74 let mut command_builder = std::process::Command::new(program_name);75 command_builder.args(tokens);76 Ok(command_builder)77 } else {78 bail!("Can not execute empty command")79 }Flat directory/module structureDavid Peterbefore adoption30c381f
lines 80–81why, one step back80 }81Move functions into SchedulerDavid Peterbefore adoption39c7736
line 82why, one step back82 pub fn get_parameters(&self) -> &[(&'a str, ParameterValue)] {Flat directory/module structureDavid Peterbefore adoption30c381f
lines 83–99why, one step back83 &self.parameters84 }8586 fn replace_parameters_in(&self, original: &str) -> String {87 let mut result = String::new();88 let mut replacements = BTreeMap::<String, String>::new();89 for (param_name, param_value) in &self.parameters {90 replacements.insert(91 format!("{{{param_name}}}", param_name = param_name),92 param_value.to_string(),93 );94 }95 let mut remaining = original;96 // Manually replace consecutive occurrences to avoid double-replacing: e.g.,97 //98 // hyperfine -L foo 'a,{bar}' -L bar 'baz,quux' 'echo {foo} {bar}'99 //Rename to get_command_lineDavid Peterbefore adoption826449b
line 100why, one step back100 // should not ever run 'echo baz baz'. See `test_get_command_line_nonoverlapping`.Flat directory/module structureDavid Peterbefore adoption30c381f
lines 101–115why, one step back101 'outer: while let Some(head) = remaining.chars().next() {102 for (k, v) in &replacements {103 if remaining.starts_with(k.as_str()) {104 result.push_str(v);105 remaining = &remaining[k.len()..];106 continue 'outer;107 }108 }109 result.push(head);110 remaining = &remaining[head.len_utf8()..];111 }112 result113 }114}115Refactor command.rsDavid Peterbefore adoption833529f
line 116why, one step back116/// A collection of commands that should be benchmarkedIntroduce Commands structDavid Peterbefore adoptiona6baf49
line 117why, one step back117pub struct Commands<'a>(Vec<Command<'a>>);Move build_commandsDavid Peterbefore adoptioncd38e9c
line 118why, one step back118Introduce Commands structDavid Peterbefore adoptiona6baf49
lines 119–125why, one step back119impl<'a> Commands<'a> {120 pub fn from_cli_arguments(matches: &'a ArgMatches) -> Result<Commands> {121 let command_names = matches.values_of("command-name");122 let command_strings = matches.values_of("command").unwrap();123124 if let Some(args) = matches.values_of("parameter-scan") {125 let step_size = matches.value_of("parameter-step-size");Refactor command.rsDavid Peterbefore adoption833529f
line 126why, one step back126 Ok(Self(Self::get_parameter_scan_commands(Introduce Commands structDavid Peterbefore adoptiona6baf49
lines 127–145why, one step back127 command_names,128 command_strings,129 args,130 step_size,131 )?))132 } else if let Some(args) = matches.values_of("parameter-list") {133 let command_names = command_names.map_or(vec![], |names| names.collect::<Vec<&str>>());134135 let args: Vec<_> = args.collect();136 let param_names_and_values: Vec<(&str, Vec<String>)> = args137 .chunks_exact(2)138 .map(|pair| {139 let name = pair[0];140 let list_str = pair[1];141 (name, tokenize(list_str))142 })143 .collect();144 {145 let duplicates =Refactor command.rsDavid Peterbefore adoption833529f
line 146why, one step back146 Self::find_duplicates(param_names_and_values.iter().map(|(name, _)| *name));Introduce Commands structDavid Peterbefore adoptiona6baf49
lines 147–149why, one step back147 if !duplicates.is_empty() {148 bail!("Duplicate parameter names: {}", &duplicates.join(", "));149 }Move build_commandsDavid Peterbefore adoptioncd38e9c
line 150why, one step back150 }Introduce Commands structDavid Peterbefore adoptiona6baf49
line 151why, one step back151 let command_list = command_strings.collect::<Vec<&str>>();Move build_commandsDavid Peterbefore adoptioncd38e9c
line 152why, one step back152Introduce Commands structDavid Peterbefore adoptiona6baf49
lines 153–163why, one step back153 let dimensions: Vec<usize> = std::iter::once(command_list.len())154 .chain(155 param_names_and_values156 .iter()157 .map(|(_, values)| values.len()),158 )159 .collect();160 let param_space_size = dimensions.iter().product();161 if param_space_size == 0 {162 return Ok(Self(Vec::new()));163 }Move build_commandsDavid Peterbefore adoptioncd38e9c
line 164why, one step back164Introduce Commands structDavid Peterbefore adoptiona6baf49
lines 165–174why, one step back165 // `--command-name` should appear exactly once or exactly B times,166 // where B is the total number of benchmarks.167 let command_name_count = command_names.len();168 if command_name_count > 1 && command_name_count != param_space_size {169 return Err(OptionsError::UnexpectedCommandNameCount(170 command_name_count,171 param_space_size,172 )173 .into());174 }Move build_commandsDavid Peterbefore adoptioncd38e9c
line 175why, one step back175Introduce Commands structDavid Peterbefore adoptiona6baf49
lines 176–184why, one step back176 let mut i = 0;177 let mut commands = Vec::with_capacity(param_space_size);178 let mut index = vec![0usize; dimensions.len()];179 'outer: loop {180 let name = command_names181 .get(i)182 .or_else(|| command_names.get(0))183 .copied();184 i += 1;Move build_commandsDavid Peterbefore adoptioncd38e9c
line 185why, one step back185Introduce Commands structDavid Peterbefore adoptiona6baf49
line 186why, one step back186 let (command_index, params_indices) = index.split_first().unwrap();Move functions into SchedulerDavid Peterbefore adoption39c7736
line 187why, one step back187 let parameters: Vec<_> = param_names_and_valuesIntroduce Commands structDavid Peterbefore adoptiona6baf49
lines 188–196why, one step back188 .iter()189 .zip(params_indices)190 .map(|((name, values), i)| (*name, ParameterValue::Text(values[*i].clone())))191 .collect();192 commands.push(Command::new_parametrized(193 name,194 command_list[*command_index],195 parameters,196 ));Move build_commandsDavid Peterbefore adoptioncd38e9c
line 197why, one step back197Introduce Commands structDavid Peterbefore adoptiona6baf49
lines 198–205why, one step back198 // Increment index, exiting loop on overflow.199 for (i, n) in index.iter_mut().zip(dimensions.iter()) {200 *i += 1;201 if *i < *n {202 continue 'outer;203 } else {204 *i = 0;205 }Move build_commandsDavid Peterbefore adoptioncd38e9c
line 206why, one step back206 }Introduce Commands structDavid Peterbefore adoptiona6baf49
line 207why, one step back207 break 'outer;Move build_commandsDavid Peterbefore adoptioncd38e9c
lines 208–209why, one step back208 }209Introduce Commands structDavid Peterbefore adoptiona6baf49
lines 210–215why, one step back210 Ok(Self(commands))211 } else {212 let command_names = command_names.map_or(vec![], |names| names.collect::<Vec<&str>>());213 if command_names.len() > command_strings.len() {214 return Err(OptionsError::TooManyCommandNames(command_strings.len()).into());215 }Move build_commandsDavid Peterbefore adoptioncd38e9c
line 216why, one step back216Introduce Commands structDavid Peterbefore adoptiona6baf49
lines 217–222why, one step back217 let command_list = command_strings.collect::<Vec<&str>>();218 let mut commands = Vec::with_capacity(command_list.len());219 for (i, s) in command_list.iter().enumerate() {220 commands.push(Command::new(command_names.get(i).copied(), s));221 }222 Ok(Self(commands))Move build_commandsDavid Peterbefore adoptioncd38e9c
lines 223–225why, one step back223 }224 }225Introduce Commands structDavid Peterbefore adoptiona6baf49
lines 226–227why, one step back226 pub fn iter(&self) -> impl Iterator<Item = &Command<'a>> {227 self.0.iter()Move build_commandsDavid Peterbefore adoptioncd38e9c
line 228why, one step back228 }Introduce Commands structDavid Peterbefore adoptiona6baf49
line 229why, one step back229Fix clippy warningDavid Peterbefore adoption250db61
line 230why, one step back230 pub fn num_commands(&self) -> usize {Introduce Commands structDavid Peterbefore adoptiona6baf49
lines 231–232why, one step back231 self.0.len()232 }Refactor command.rsDavid Peterbefore adoption833529f
lines 233–332why, one step back233234 /// Finds all the strings that appear multiple times in the input iterator, returning them in235 /// sorted order. If no string appears more than once, the result is an empty vector.236 fn find_duplicates<'b, I: IntoIterator<Item = &'b str>>(i: I) -> Vec<&'b str> {237 let mut counts = BTreeMap::<&'b str, usize>::new();238 for s in i {239 *counts.entry(s).or_default() += 1;240 }241 counts242 .into_iter()243 .filter_map(|(k, n)| if n > 1 { Some(k) } else { None })244 .collect()245 }246247 fn build_parameter_scan_commands<'b, T: Numeric>(248 param_name: &'b str,249 param_min: T,250 param_max: T,251 step: T,252 command_names: Vec<&'b str>,253 command_strings: Vec<&'b str>,254 ) -> Result<Vec<Command<'b>>, ParameterScanError> {255 let param_range = RangeStep::new(param_min, param_max, step)?;256 let param_count = param_range.size_hint().1.unwrap();257 let command_name_count = command_names.len();258259 // `--command-name` should appear exactly once or exactly B times,260 // where B is the total number of benchmarks.261 if command_name_count > 1 && command_name_count != param_count {262 return Err(ParameterScanError::UnexpectedCommandNameCount(263 command_name_count,264 param_count,265 ));266 }267268 let mut i = 0;269 let mut commands = vec![];270 for value in param_range {271 for cmd in &command_strings {272 let name = command_names273 .get(i)274 .or_else(|| command_names.get(0))275 .copied();276 commands.push(Command::new_parametrized(277 name,278 cmd,279 vec![(param_name, ParameterValue::Numeric(value.into()))],280 ));281 i += 1;282 }283 }284 Ok(commands)285 }286287 fn get_parameter_scan_commands<'b>(288 command_names: Option<Values<'b>>,289 command_strings: Values<'b>,290 mut vals: clap::Values<'b>,291 step: Option<&str>,292 ) -> Result<Vec<Command<'b>>, ParameterScanError> {293 let command_names = command_names.map_or(vec![], |names| names.collect::<Vec<&str>>());294 let command_strings = command_strings.collect::<Vec<&str>>();295 let param_name = vals.next().unwrap();296 let param_min = vals.next().unwrap();297 let param_max = vals.next().unwrap();298299 // attempt to parse as integers300 if let (Ok(param_min), Ok(param_max), Ok(step)) = (301 param_min.parse::<i32>(),302 param_max.parse::<i32>(),303 step.unwrap_or("1").parse::<i32>(),304 ) {305 return Self::build_parameter_scan_commands(306 param_name,307 param_min,308 param_max,309 step,310 command_names,311 command_strings,312 );313 }314315 // try parsing them as decimals316 let param_min = Decimal::from_str(param_min)?;317 let param_max = Decimal::from_str(param_max)?;318319 if step.is_none() {320 return Err(ParameterScanError::StepRequired);321 }322323 let step = Decimal::from_str(step.unwrap())?;324 Self::build_parameter_scan_commands(325 param_name,326 param_min,327 param_max,328 step,329 command_names,330 command_strings,331 )332 }Move build_commandsDavid Peterbefore adoptioncd38e9c
lines 333–334why, one step back333}334Flat directory/module structureDavid Peterbefore adoption30c381f
line 335why, one step back335#[test]Rename to get_command_lineDavid Peterbefore adoption826449b
line 336why, one step back336fn test_get_command_line_nonoverlapping() {Flat directory/module structureDavid Peterbefore adoption30c381f
lines 337–344why, one step back337 let cmd = Command::new_parametrized(338 None,339 "echo {foo} {bar}",340 vec![341 ("foo", ParameterValue::Text("{bar} baz".into())),342 ("bar", ParameterValue::Text("quux".into())),343 ],344 );Rename to get_command_lineDavid Peterbefore adoption826449b
line 345why, one step back345 assert_eq!(cmd.get_command_line(), "echo {bar} baz quux");Flat directory/module structureDavid Peterbefore adoption30c381f
lines 346–362why, one step back346}347348#[test]349fn test_get_parameterized_command_name() {350 let cmd = Command::new_parametrized(351 Some("name-{bar}-{foo}"),352 "echo {foo} {bar}",353 vec![354 ("foo", ParameterValue::Text("baz".into())),355 ("bar", ParameterValue::Text("quux".into())),356 ],357 );358 assert_eq!(cmd.get_name(), "name-quux-baz");359}360361impl<'a> fmt::Display for Command<'a> {362 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {Rename to get_command_lineDavid Peterbefore adoption826449b
line 363why, one step back363 write!(f, "{}", self.get_command_line())Flat directory/module structureDavid Peterbefore adoption30c381f
line 364why, one step back364 }Move build_commandsDavid Peterbefore adoptioncd38e9c
lines 365–368why, one step back365}366367#[test]368fn test_build_commands_cross_product() {Update dependenciesDavid Peterbefore adoptionf2f1dd9
line 369why, one step back369 use crate::cli::get_cli_arguments;Move build_commandsDavid Peterbefore adoptioncd38e9c
line 370why, one step back370Introduce Commands structDavid Peterbefore adoptiona6baf49
line 371why, one step back371 let matches = get_cli_arguments(vec![Move build_commandsDavid Peterbefore adoptioncd38e9c
lines 372–381why, one step back372 "hyperfine",373 "-L",374 "par1",375 "a,b",376 "-L",377 "par2",378 "z,y",379 "echo {par1} {par2}",380 "printf '%s\n' {par1} {par2}",381 ]);Introduce Commands structDavid Peterbefore adoptiona6baf49
line 382why, one step back382 let result = Commands::from_cli_arguments(&matches).unwrap().0;Move build_commandsDavid Peterbefore adoptioncd38e9c
lines 383–406why, one step back383384 // Iteration order: command list first, then parameters in listed order (here, "par1" before385 // "par2", which is distinct from their sorted order), with parameter values in listed order.386 let pv = |s: &str| ParameterValue::Text(s.to_string());387 let cmd = |cmd: usize, par1: &str, par2: &str| {388 let expression = ["echo {par1} {par2}", "printf '%s\n' {par1} {par2}"][cmd];389 let params = vec![("par1", pv(par1)), ("par2", pv(par2))];390 Command::new_parametrized(None, expression, params)391 };392 let expected = vec![393 cmd(0, "a", "z"),394 cmd(1, "a", "z"),395 cmd(0, "b", "z"),396 cmd(1, "b", "z"),397 cmd(0, "a", "y"),398 cmd(1, "a", "y"),399 cmd(0, "b", "y"),400 cmd(1, "b", "y"),401 ];402 assert_eq!(result, expected);403}404405#[test]406fn test_build_parameter_list_commands() {Update dependenciesDavid Peterbefore adoptionf2f1dd9
line 407why, one step back407 use crate::cli::get_cli_arguments;Move build_commandsDavid Peterbefore adoptioncd38e9c
line 408why, one step back408Introduce Commands structDavid Peterbefore adoptiona6baf49
line 409why, one step back409 let matches = get_cli_arguments(vec![Move build_commandsDavid Peterbefore adoptioncd38e9c
lines 410–417why, one step back410 "hyperfine",411 "echo {foo}",412 "--parameter-list",413 "foo",414 "1,2",415 "--command-name",416 "name-{foo}",417 ]);Introduce Commands structDavid Peterbefore adoptiona6baf49
line 418why, one step back418 let commands = Commands::from_cli_arguments(&matches).unwrap().0;Move build_commandsDavid Peterbefore adoptioncd38e9c
lines 419–421why, one step back419 assert_eq!(commands.len(), 2);420 assert_eq!(commands[0].get_name(), "name-1");421 assert_eq!(commands[1].get_name(), "name-2");Rename to get_command_lineDavid Peterbefore adoption826449b
lines 422–423why, one step back422 assert_eq!(commands[0].get_command_line(), "echo 1");423 assert_eq!(commands[1].get_command_line(), "echo 2");Move build_commandsDavid Peterbefore adoptioncd38e9c
lines 424–426why, one step back424}425426#[test]Refactor command.rsDavid Peterbefore adoption833529f
line 427why, one step back427fn test_build_parameter_scan_commands() {Update dependenciesDavid Peterbefore adoptionf2f1dd9
line 428why, one step back428 use crate::cli::get_cli_arguments;Introduce Commands structDavid Peterbefore adoptiona6baf49
line 429why, one step back429 let matches = get_cli_arguments(vec![Move build_commandsDavid Peterbefore adoptioncd38e9c
lines 430–440why, one step back430 "hyperfine",431 "echo {val}",432 "--parameter-scan",433 "val",434 "1",435 "2",436 "--parameter-step-size",437 "1",438 "--command-name",439 "name-{val}",440 ]);Introduce Commands structDavid Peterbefore adoptiona6baf49
line 441why, one step back441 let commands = Commands::from_cli_arguments(&matches).unwrap().0;Move build_commandsDavid Peterbefore adoptioncd38e9c
lines 442–444why, one step back442 assert_eq!(commands.len(), 2);443 assert_eq!(commands[0].get_name(), "name-1");444 assert_eq!(commands[1].get_name(), "name-2");Rename to get_command_lineDavid Peterbefore adoption826449b
lines 445–446why, one step back445 assert_eq!(commands[0].get_command_line(), "echo 1");446 assert_eq!(commands[1].get_command_line(), "echo 2");Split range into range_step and commandsDavid Peterbefore adoption6db82cd
lines 447–449why, one step back447}448449#[test]Refactor command.rsDavid Peterbefore adoption833529f
lines 450–459why, one step back450fn test_parameter_scan_commands_int() {451 let commands = Commands::build_parameter_scan_commands(452 "val",453 1i32,454 7i32,455 3i32,456 vec![],457 vec!["echo {val}"],458 )459 .unwrap();Split range into range_step and commandsDavid Peterbefore adoption6db82cd
lines 460–461why, one step back460 assert_eq!(commands.len(), 3);461 assert_eq!(commands[2].get_name(), "echo 7");Rename to get_command_lineDavid Peterbefore adoption826449b
line 462why, one step back462 assert_eq!(commands[2].get_command_line(), "echo 7");Split range into range_step and commandsDavid Peterbefore adoption6db82cd
lines 463–465why, one step back463}464465#[test]Refactor command.rsDavid Peterbefore adoption833529f
line 466why, one step back466fn test_parameter_scan_commands_decimal() {Split range into range_step and commandsDavid Peterbefore adoption6db82cd
lines 467–470why, one step back467 let param_min = Decimal::from_str("0").unwrap();468 let param_max = Decimal::from_str("1").unwrap();469 let step = Decimal::from_str("0.33").unwrap();470Refactor command.rsDavid Peterbefore adoption833529f
lines 471–472why, one step back471 let commands = Commands::build_parameter_scan_commands(472 "val",Split range into range_step and commandsDavid Peterbefore adoption6db82cd
lines 473–481why, one step back473 param_min,474 param_max,475 step,476 vec![],477 vec!["echo {val}"],478 )479 .unwrap();480 assert_eq!(commands.len(), 4);481 assert_eq!(commands[3].get_name(), "echo 0.99");Rename to get_command_lineDavid Peterbefore adoption826449b
line 482why, one step back482 assert_eq!(commands[3].get_command_line(), "echo 0.99");Split range into range_step and commandsDavid Peterbefore adoption6db82cd
lines 483–485why, one step back483}484485#[test]Refactor command.rsDavid Peterbefore adoption833529f
lines 486–488why, one step back486fn test_parameterr_scan_commands_names() {487 let commands = Commands::build_parameter_scan_commands(488 "val",Split range into range_step and commandsDavid Peterbefore adoption6db82cd
lines 489–505why, one step back489 1i32,490 3i32,491 1i32,492 vec!["name-{val}"],493 vec!["echo {val}"],494 )495 .unwrap();496 assert_eq!(commands.len(), 3);497 let command_names = commands498 .iter()499 .map(|c| c.get_name())500 .collect::<Vec<String>>();501 assert_eq!(command_names, vec!["name-1", "name-2", "name-3"]);502}503504#[test]505fn test_get_specified_command_names() {Refactor command.rsDavid Peterbefore adoption833529f
lines 506–507why, one step back506 let commands = Commands::build_parameter_scan_commands(507 "val",Split range into range_step and commandsDavid Peterbefore adoption6db82cd
lines 508–524why, one step back508 1i32,509 3i32,510 1i32,511 vec!["name-a", "name-b", "name-c"],512 vec!["echo {val}"],513 )514 .unwrap();515 assert_eq!(commands.len(), 3);516 let command_names = commands517 .iter()518 .map(|c| c.get_name())519 .collect::<Vec<String>>();520 assert_eq!(command_names, vec!["name-a", "name-b", "name-c"]);521}522523#[test]524fn test_different_command_name_count_with_parameters() {Refactor command.rsDavid Peterbefore adoption833529f
lines 525–526why, one step back525 let result = Commands::build_parameter_scan_commands(526 "val",Split range into range_step and commandsDavid Peterbefore adoption6db82cd
lines 527–532why, one step back527 1i32,528 3i32,529 1i32,530 vec!["name-1", "name-2"],531 vec!["echo {val}"],532 );Refactor command.rsDavid Peterbefore adoption833529f
lines 533–536why, one step back533 assert!(matches!(534 result.unwrap_err(),535 ParameterScanError::UnexpectedCommandNameCount(2, 3)536 ));Flat directory/module structureDavid Peterbefore adoption30c381f
line 537why, one step back537}