command.rs
This file
Path
src/command.rs
535 lines · 16.9 KiB · Rust
Last changed by
update to clap 4Benjamin Rombautbefore adoption8d38ef3
History of this fileTake it
The walk stopped after 200 commits: lines older than cb33468 point at it.
Bump rust_decimal from 1.17.0 to 1.19.0dependabot[bot]before adoptioncb33468
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;Bump rust_decimal from 1.17.0 to 1.19.0dependabot[bot]before adoptioncb33468
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
line 12why, one step back12update to clap 4Benjamin Rombautbefore adoption8d38ef3
line 13why, one step back13use clap::{ArgMatches, parser::ValuesRef};Move build_commandsDavid Peterbefore adoptioncd38e9c
line 14why, one step back14New parameter moduleDavid Peterbefore adoption47091a5
lines 15–16why, one step back15use crate::parameter::tokenize::tokenize;16use crate::parameter::ParameterValue;Bump rust_decimal from 1.17.0 to 1.19.0dependabot[bot]before adoptioncb33468
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
line 19why, one step back19use rust_decimal::Decimal;Move build_commandsDavid Peterbefore adoptioncd38e9c
line 20why, one step back20Bump rust_decimal from 1.17.0 to 1.19.0dependabot[bot]before adoptioncb33468
lines 21–30why, one step back21/// A command that should be benchmarked.22#[derive(Debug, Clone, PartialEq, Eq)]23pub struct Command<'a> {24 /// The command name (without parameter substitution)25 name: Option<&'a str>,2627 /// The command that should be executed (without parameter substitution)28 expression: &'a str,2930 /// Zero or more parameter values.Move functions into SchedulerDavid Peterbefore adoption39c7736
line 31why, one step back31 parameters: Vec<ParameterNameAndValue<'a>>,Bump rust_decimal from 1.17.0 to 1.19.0dependabot[bot]before adoptioncb33468
lines 32–45why, one step back32}3334impl<'a> Command<'a> {35 pub fn new(name: Option<&'a str>, expression: &'a str) -> Command<'a> {36 Command {37 name,38 expression,39 parameters: Vec::new(),40 }41 }4243 pub fn new_parametrized(44 name: Option<&'a str>,45 expression: &'a str,Move functions into SchedulerDavid Peterbefore adoption39c7736
line 46why, one step back46 parameters: impl IntoIterator<Item = ParameterNameAndValue<'a>>,Bump rust_decimal from 1.17.0 to 1.19.0dependabot[bot]before adoptioncb33468
lines 47–50why, one step back47 ) -> Command<'a> {48 Command {49 name,50 expression,Move functions into SchedulerDavid Peterbefore adoption39c7736
line 51why, one step back51 parameters: parameters.into_iter().collect(),Bump rust_decimal from 1.17.0 to 1.19.0dependabot[bot]before adoptioncb33468
lines 52–56why, one step back52 }53 }5455 pub fn get_name(&self) -> String {56 self.name.map_or_else(Rename to get_command_lineDavid Peterbefore adoption826449b
line 57why, one step back57 || self.get_command_line(),Bump rust_decimal from 1.17.0 to 1.19.0dependabot[bot]before adoptioncb33468
lines 58–61why, one step back58 |name| self.replace_parameters_in(name),59 )60 }61Rename to get_command_lineDavid Peterbefore adoption826449b
line 62why, one step back62 pub fn get_command_line(&self) -> String {Bump rust_decimal from 1.17.0 to 1.19.0dependabot[bot]before adoptioncb33468
line 63why, one step back63 self.replace_parameters_in(self.expression)Use raw executor by default, skip intermediate shellDavid Peterbefore adoptiond9418e0
lines 64–78why, one step back64 }6566 pub fn get_command(&self) -> Result<std::process::Command> {67 let command_line = self.get_command_line();68 let mut tokens = shell_words::split(&command_line)69 .with_context(|| format!("Failed to parse command '{}'", command_line))?70 .into_iter();7172 if let Some(program_name) = tokens.next() {73 let mut command_builder = std::process::Command::new(program_name);74 command_builder.args(tokens);75 Ok(command_builder)76 } else {77 bail!("Can not execute empty command")78 }Bump rust_decimal from 1.17.0 to 1.19.0dependabot[bot]before adoptioncb33468
lines 79–80why, one step back79 }80Move functions into SchedulerDavid Peterbefore adoption39c7736
line 81why, one step back81 pub fn get_parameters(&self) -> &[(&'a str, ParameterValue)] {Bump rust_decimal from 1.17.0 to 1.19.0dependabot[bot]before adoptioncb33468
lines 82–98why, one step back82 &self.parameters83 }8485 fn replace_parameters_in(&self, original: &str) -> String {86 let mut result = String::new();87 let mut replacements = BTreeMap::<String, String>::new();88 for (param_name, param_value) in &self.parameters {89 replacements.insert(90 format!("{{{param_name}}}", param_name = param_name),91 param_value.to_string(),92 );93 }94 let mut remaining = original;95 // Manually replace consecutive occurrences to avoid double-replacing: e.g.,96 //97 // hyperfine -L foo 'a,{bar}' -L bar 'baz,quux' 'echo {foo} {bar}'98 //Rename to get_command_lineDavid Peterbefore adoption826449b
line 99why, one step back99 // should not ever run 'echo baz baz'. See `test_get_command_line_nonoverlapping`.Bump rust_decimal from 1.17.0 to 1.19.0dependabot[bot]before adoptioncb33468
lines 100–114why, one step back100 'outer: while let Some(head) = remaining.chars().next() {101 for (k, v) in &replacements {102 if remaining.starts_with(k.as_str()) {103 result.push_str(v);104 remaining = &remaining[k.len()..];105 continue 'outer;106 }107 }108 result.push(head);109 remaining = &remaining[head.len_utf8()..];110 }111 result112 }113}114Refactor command.rsDavid Peterbefore adoption833529f
line 115why, one step back115/// A collection of commands that should be benchmarkedIntroduce Commands structDavid Peterbefore adoptiona6baf49
line 116why, one step back116pub struct Commands<'a>(Vec<Command<'a>>);Move build_commandsDavid Peterbefore adoptioncd38e9c
line 117why, one step back117Introduce Commands structDavid Peterbefore adoptiona6baf49
lines 118–119why, one step back118impl<'a> Commands<'a> {119 pub fn from_cli_arguments(matches: &'a ArgMatches) -> Result<Commands> {update to clap 4Benjamin Rombautbefore adoption8d38ef3
lines 120–121why, one step back120 let command_names = matches.get_many::<String>("command-name");121 let command_strings = matches.get_many::<String>("command").unwrap_or_default().map(|v| v.as_str()).collect::<Vec<_>>();Introduce Commands structDavid Peterbefore adoptiona6baf49
line 122why, one step back122update to clap 4Benjamin Rombautbefore adoption8d38ef3
line 123why, one step back123 if let Some(args) = matches.get_many::<String>("parameter-scan") {add clap deprecation noticesBenjamin Rombautbefore adoption5fcb716
line 124why, one step back124 let step_size = matches.get_one::<String>("parameter-step-size").map(|s| s.as_str());Refactor command.rsDavid Peterbefore adoption833529f
line 125why, one step back125 Ok(Self(Self::get_parameter_scan_commands(Introduce Commands structDavid Peterbefore adoptiona6baf49
lines 126–130why, one step back126 command_names,127 command_strings,128 args,129 step_size,130 )?))update to clap 4Benjamin Rombautbefore adoption8d38ef3
lines 131–133why, one step back131 } else if let Some(args) = matches.get_many::<String>("parameter-list") {132 let command_names = command_names.map_or(vec![], |names| names.map(|v| v.as_str()).collect::<Vec<_>>());133 let args: Vec<_> = args.map(|v| v.as_str()).collect::<Vec<_>>();Introduce Commands structDavid Peterbefore adoptiona6baf49
lines 134–143why, one step back134 let param_names_and_values: Vec<(&str, Vec<String>)> = args135 .chunks_exact(2)136 .map(|pair| {137 let name = pair[0];138 let list_str = pair[1];139 (name, tokenize(list_str))140 })141 .collect();142 {143 let duplicates =Refactor command.rsDavid Peterbefore adoption833529f
line 144why, one step back144 Self::find_duplicates(param_names_and_values.iter().map(|(name, _)| *name));Introduce Commands structDavid Peterbefore adoptiona6baf49
lines 145–147why, one step back145 if !duplicates.is_empty() {146 bail!("Duplicate parameter names: {}", &duplicates.join(", "));147 }Move build_commandsDavid Peterbefore adoptioncd38e9c
line 148why, one step back148 }update to clap 4Benjamin Rombautbefore adoption8d38ef3
line 149why, one step back149 let command_list = command_strings;Move build_commandsDavid Peterbefore adoptioncd38e9c
line 150why, one step back150Introduce Commands structDavid Peterbefore adoptiona6baf49
lines 151–161why, one step back151 let dimensions: Vec<usize> = std::iter::once(command_list.len())152 .chain(153 param_names_and_values154 .iter()155 .map(|(_, values)| values.len()),156 )157 .collect();158 let param_space_size = dimensions.iter().product();159 if param_space_size == 0 {160 return Ok(Self(Vec::new()));161 }Move build_commandsDavid Peterbefore adoptioncd38e9c
line 162why, one step back162Introduce Commands structDavid Peterbefore adoptiona6baf49
lines 163–172why, one step back163 // `--command-name` should appear exactly once or exactly B times,164 // where B is the total number of benchmarks.165 let command_name_count = command_names.len();166 if command_name_count > 1 && command_name_count != param_space_size {167 return Err(OptionsError::UnexpectedCommandNameCount(168 command_name_count,169 param_space_size,170 )171 .into());172 }Move build_commandsDavid Peterbefore adoptioncd38e9c
line 173why, one step back173Introduce Commands structDavid Peterbefore adoptiona6baf49
lines 174–179why, one step back174 let mut i = 0;175 let mut commands = Vec::with_capacity(param_space_size);176 let mut index = vec![0usize; dimensions.len()];177 'outer: loop {178 let name = command_names179 .get(i)Fix clippy suggestionsDavid Peterbefore adoptionc7e5694
line 180why, one step back180 .or_else(|| command_names.first())Introduce Commands structDavid Peterbefore adoptiona6baf49
lines 181–182why, one step back181 .copied();182 i += 1;Move build_commandsDavid Peterbefore adoptioncd38e9c
line 183why, one step back183Introduce Commands structDavid Peterbefore adoptiona6baf49
line 184why, one step back184 let (command_index, params_indices) = index.split_first().unwrap();Move functions into SchedulerDavid Peterbefore adoption39c7736
line 185why, one step back185 let parameters: Vec<_> = param_names_and_valuesIntroduce Commands structDavid Peterbefore adoptiona6baf49
lines 186–194why, one step back186 .iter()187 .zip(params_indices)188 .map(|((name, values), i)| (*name, ParameterValue::Text(values[*i].clone())))189 .collect();190 commands.push(Command::new_parametrized(191 name,192 command_list[*command_index],193 parameters,194 ));Move build_commandsDavid Peterbefore adoptioncd38e9c
line 195why, one step back195Introduce Commands structDavid Peterbefore adoptiona6baf49
lines 196–203why, one step back196 // Increment index, exiting loop on overflow.197 for (i, n) in index.iter_mut().zip(dimensions.iter()) {198 *i += 1;199 if *i < *n {200 continue 'outer;201 } else {202 *i = 0;203 }Move build_commandsDavid Peterbefore adoptioncd38e9c
line 204why, one step back204 }Introduce Commands structDavid Peterbefore adoptiona6baf49
line 205why, one step back205 break 'outer;Move build_commandsDavid Peterbefore adoptioncd38e9c
lines 206–207why, one step back206 }207Introduce Commands structDavid Peterbefore adoptiona6baf49
lines 208–209why, one step back208 Ok(Self(commands))209 } else {update to clap 4Benjamin Rombautbefore adoption8d38ef3
line 210why, one step back210 let command_names = command_names.map_or(vec![], |names| names.map(|v| v.as_str()).collect::<Vec<_>>());Introduce Commands structDavid Peterbefore adoptiona6baf49
lines 211–213why, one step back211 if command_names.len() > command_strings.len() {212 return Err(OptionsError::TooManyCommandNames(command_strings.len()).into());213 }Move build_commandsDavid Peterbefore adoptioncd38e9c
line 214why, one step back214update to clap 4Benjamin Rombautbefore adoption8d38ef3
line 215why, one step back215 let command_list = command_strings;Introduce Commands structDavid Peterbefore adoptiona6baf49
lines 216–220why, one step back216 let mut commands = Vec::with_capacity(command_list.len());217 for (i, s) in command_list.iter().enumerate() {218 commands.push(Command::new(command_names.get(i).copied(), s));219 }220 Ok(Self(commands))Move build_commandsDavid Peterbefore adoptioncd38e9c
lines 221–223why, one step back221 }222 }223Introduce Commands structDavid Peterbefore adoptiona6baf49
lines 224–225why, one step back224 pub fn iter(&self) -> impl Iterator<Item = &Command<'a>> {225 self.0.iter()Move build_commandsDavid Peterbefore adoptioncd38e9c
line 226why, one step back226 }Introduce Commands structDavid Peterbefore adoptiona6baf49
line 227why, one step back227Fix clippy warningDavid Peterbefore adoption250db61
line 228why, one step back228 pub fn num_commands(&self) -> usize {Introduce Commands structDavid Peterbefore adoptiona6baf49
lines 229–230why, one step back229 self.0.len()230 }Refactor command.rsDavid Peterbefore adoption833529f
lines 231–271why, one step back231232 /// Finds all the strings that appear multiple times in the input iterator, returning them in233 /// sorted order. If no string appears more than once, the result is an empty vector.234 fn find_duplicates<'b, I: IntoIterator<Item = &'b str>>(i: I) -> Vec<&'b str> {235 let mut counts = BTreeMap::<&'b str, usize>::new();236 for s in i {237 *counts.entry(s).or_default() += 1;238 }239 counts240 .into_iter()241 .filter_map(|(k, n)| if n > 1 { Some(k) } else { None })242 .collect()243 }244245 fn build_parameter_scan_commands<'b, T: Numeric>(246 param_name: &'b str,247 param_min: T,248 param_max: T,249 step: T,250 command_names: Vec<&'b str>,251 command_strings: Vec<&'b str>,252 ) -> Result<Vec<Command<'b>>, ParameterScanError> {253 let param_range = RangeStep::new(param_min, param_max, step)?;254 let param_count = param_range.size_hint().1.unwrap();255 let command_name_count = command_names.len();256257 // `--command-name` should appear exactly once or exactly B times,258 // where B is the total number of benchmarks.259 if command_name_count > 1 && command_name_count != param_count {260 return Err(ParameterScanError::UnexpectedCommandNameCount(261 command_name_count,262 param_count,263 ));264 }265266 let mut i = 0;267 let mut commands = vec![];268 for value in param_range {269 for cmd in &command_strings {270 let name = command_names271 .get(i)Fix clippy suggestionsDavid Peterbefore adoptionc7e5694
line 272why, one step back272 .or_else(|| command_names.first())Refactor command.rsDavid Peterbefore adoption833529f
lines 273–285why, one step back273 .copied();274 commands.push(Command::new_parametrized(275 name,276 cmd,277 vec![(param_name, ParameterValue::Numeric(value.into()))],278 ));279 i += 1;280 }281 }282 Ok(commands)283 }284285 fn get_parameter_scan_commands<'b>(update to clap 4Benjamin Rombautbefore adoption8d38ef3
lines 286–288why, one step back286 command_names: Option<ValuesRef<'b, String>>,287 command_strings: Vec<&'b str>,288 mut vals: ValuesRef<'b, String>,Refactor command.rsDavid Peterbefore adoption833529f
lines 289–290why, one step back289 step: Option<&str>,290 ) -> Result<Vec<Command<'b>>, ParameterScanError> {update to clap 4Benjamin Rombautbefore adoption8d38ef3
lines 291–295why, one step back291 let command_names = command_names.map_or(vec![], |names| names.map(|v| v.as_str()).collect::<Vec<_>>());292 let command_strings = command_strings;293 let param_name = vals.next().unwrap().as_str();294 let param_min = vals.next().unwrap().as_str();295 let param_max = vals.next().unwrap().as_str();Refactor command.rsDavid Peterbefore adoption833529f
lines 296–330why, one step back296297 // attempt to parse as integers298 if let (Ok(param_min), Ok(param_max), Ok(step)) = (299 param_min.parse::<i32>(),300 param_max.parse::<i32>(),301 step.unwrap_or("1").parse::<i32>(),302 ) {303 return Self::build_parameter_scan_commands(304 param_name,305 param_min,306 param_max,307 step,308 command_names,309 command_strings,310 );311 }312313 // try parsing them as decimals314 let param_min = Decimal::from_str(param_min)?;315 let param_max = Decimal::from_str(param_max)?;316317 if step.is_none() {318 return Err(ParameterScanError::StepRequired);319 }320321 let step = Decimal::from_str(step.unwrap())?;322 Self::build_parameter_scan_commands(323 param_name,324 param_min,325 param_max,326 step,327 command_names,328 command_strings,329 )330 }Move build_commandsDavid Peterbefore adoptioncd38e9c
lines 331–332why, one step back331}332Bump rust_decimal from 1.17.0 to 1.19.0dependabot[bot]before adoptioncb33468
line 333why, one step back333#[test]Rename to get_command_lineDavid Peterbefore adoption826449b
line 334why, one step back334fn test_get_command_line_nonoverlapping() {Bump rust_decimal from 1.17.0 to 1.19.0dependabot[bot]before adoptioncb33468
lines 335–342why, one step back335 let cmd = Command::new_parametrized(336 None,337 "echo {foo} {bar}",338 vec![339 ("foo", ParameterValue::Text("{bar} baz".into())),340 ("bar", ParameterValue::Text("quux".into())),341 ],342 );Rename to get_command_lineDavid Peterbefore adoption826449b
line 343why, one step back343 assert_eq!(cmd.get_command_line(), "echo {bar} baz quux");Bump rust_decimal from 1.17.0 to 1.19.0dependabot[bot]before adoptioncb33468
lines 344–360why, one step back344}345346#[test]347fn test_get_parameterized_command_name() {348 let cmd = Command::new_parametrized(349 Some("name-{bar}-{foo}"),350 "echo {foo} {bar}",351 vec![352 ("foo", ParameterValue::Text("baz".into())),353 ("bar", ParameterValue::Text("quux".into())),354 ],355 );356 assert_eq!(cmd.get_name(), "name-quux-baz");357}358359impl<'a> fmt::Display for Command<'a> {360 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {Rename to get_command_lineDavid Peterbefore adoption826449b
line 361why, one step back361 write!(f, "{}", self.get_command_line())Bump rust_decimal from 1.17.0 to 1.19.0dependabot[bot]before adoptioncb33468
line 362why, one step back362 }Move build_commandsDavid Peterbefore adoptioncd38e9c
lines 363–366why, one step back363}364365#[test]366fn test_build_commands_cross_product() {Update dependenciesDavid Peterbefore adoptionf2f1dd9
line 367why, one step back367 use crate::cli::get_cli_arguments;Move build_commandsDavid Peterbefore adoptioncd38e9c
line 368why, one step back368Introduce Commands structDavid Peterbefore adoptiona6baf49
line 369why, one step back369 let matches = get_cli_arguments(vec![Move build_commandsDavid Peterbefore adoptioncd38e9c
lines 370–379why, one step back370 "hyperfine",371 "-L",372 "par1",373 "a,b",374 "-L",375 "par2",376 "z,y",377 "echo {par1} {par2}",378 "printf '%s\n' {par1} {par2}",379 ]);Introduce Commands structDavid Peterbefore adoptiona6baf49
line 380why, one step back380 let result = Commands::from_cli_arguments(&matches).unwrap().0;Move build_commandsDavid Peterbefore adoptioncd38e9c
lines 381–404why, one step back381382 // Iteration order: command list first, then parameters in listed order (here, "par1" before383 // "par2", which is distinct from their sorted order), with parameter values in listed order.384 let pv = |s: &str| ParameterValue::Text(s.to_string());385 let cmd = |cmd: usize, par1: &str, par2: &str| {386 let expression = ["echo {par1} {par2}", "printf '%s\n' {par1} {par2}"][cmd];387 let params = vec![("par1", pv(par1)), ("par2", pv(par2))];388 Command::new_parametrized(None, expression, params)389 };390 let expected = vec![391 cmd(0, "a", "z"),392 cmd(1, "a", "z"),393 cmd(0, "b", "z"),394 cmd(1, "b", "z"),395 cmd(0, "a", "y"),396 cmd(1, "a", "y"),397 cmd(0, "b", "y"),398 cmd(1, "b", "y"),399 ];400 assert_eq!(result, expected);401}402403#[test]404fn test_build_parameter_list_commands() {Update dependenciesDavid Peterbefore adoptionf2f1dd9
line 405why, one step back405 use crate::cli::get_cli_arguments;Move build_commandsDavid Peterbefore adoptioncd38e9c
line 406why, one step back406Introduce Commands structDavid Peterbefore adoptiona6baf49
line 407why, one step back407 let matches = get_cli_arguments(vec![Move build_commandsDavid Peterbefore adoptioncd38e9c
lines 408–415why, one step back408 "hyperfine",409 "echo {foo}",410 "--parameter-list",411 "foo",412 "1,2",413 "--command-name",414 "name-{foo}",415 ]);Introduce Commands structDavid Peterbefore adoptiona6baf49
line 416why, one step back416 let commands = Commands::from_cli_arguments(&matches).unwrap().0;Move build_commandsDavid Peterbefore adoptioncd38e9c
lines 417–419why, one step back417 assert_eq!(commands.len(), 2);418 assert_eq!(commands[0].get_name(), "name-1");419 assert_eq!(commands[1].get_name(), "name-2");Rename to get_command_lineDavid Peterbefore adoption826449b
lines 420–421why, one step back420 assert_eq!(commands[0].get_command_line(), "echo 1");421 assert_eq!(commands[1].get_command_line(), "echo 2");Move build_commandsDavid Peterbefore adoptioncd38e9c
lines 422–424why, one step back422}423424#[test]Refactor command.rsDavid Peterbefore adoption833529f
line 425why, one step back425fn test_build_parameter_scan_commands() {Update dependenciesDavid Peterbefore adoptionf2f1dd9
line 426why, one step back426 use crate::cli::get_cli_arguments;Introduce Commands structDavid Peterbefore adoptiona6baf49
line 427why, one step back427 let matches = get_cli_arguments(vec![Move build_commandsDavid Peterbefore adoptioncd38e9c
lines 428–438why, one step back428 "hyperfine",429 "echo {val}",430 "--parameter-scan",431 "val",432 "1",433 "2",434 "--parameter-step-size",435 "1",436 "--command-name",437 "name-{val}",438 ]);Introduce Commands structDavid Peterbefore adoptiona6baf49
line 439why, one step back439 let commands = Commands::from_cli_arguments(&matches).unwrap().0;Move build_commandsDavid Peterbefore adoptioncd38e9c
lines 440–442why, one step back440 assert_eq!(commands.len(), 2);441 assert_eq!(commands[0].get_name(), "name-1");442 assert_eq!(commands[1].get_name(), "name-2");Rename to get_command_lineDavid Peterbefore adoption826449b
lines 443–444why, one step back443 assert_eq!(commands[0].get_command_line(), "echo 1");444 assert_eq!(commands[1].get_command_line(), "echo 2");Split range into range_step and commandsDavid Peterbefore adoption6db82cd
lines 445–447why, one step back445}446447#[test]Refactor command.rsDavid Peterbefore adoption833529f
lines 448–457why, one step back448fn test_parameter_scan_commands_int() {449 let commands = Commands::build_parameter_scan_commands(450 "val",451 1i32,452 7i32,453 3i32,454 vec![],455 vec!["echo {val}"],456 )457 .unwrap();Split range into range_step and commandsDavid Peterbefore adoption6db82cd
lines 458–459why, one step back458 assert_eq!(commands.len(), 3);459 assert_eq!(commands[2].get_name(), "echo 7");Rename to get_command_lineDavid Peterbefore adoption826449b
line 460why, one step back460 assert_eq!(commands[2].get_command_line(), "echo 7");Split range into range_step and commandsDavid Peterbefore adoption6db82cd
lines 461–463why, one step back461}462463#[test]Refactor command.rsDavid Peterbefore adoption833529f
line 464why, one step back464fn test_parameter_scan_commands_decimal() {Split range into range_step and commandsDavid Peterbefore adoption6db82cd
lines 465–468why, one step back465 let param_min = Decimal::from_str("0").unwrap();466 let param_max = Decimal::from_str("1").unwrap();467 let step = Decimal::from_str("0.33").unwrap();468Refactor command.rsDavid Peterbefore adoption833529f
lines 469–470why, one step back469 let commands = Commands::build_parameter_scan_commands(470 "val",Split range into range_step and commandsDavid Peterbefore adoption6db82cd
lines 471–479why, one step back471 param_min,472 param_max,473 step,474 vec![],475 vec!["echo {val}"],476 )477 .unwrap();478 assert_eq!(commands.len(), 4);479 assert_eq!(commands[3].get_name(), "echo 0.99");Rename to get_command_lineDavid Peterbefore adoption826449b
line 480why, one step back480 assert_eq!(commands[3].get_command_line(), "echo 0.99");Split range into range_step and commandsDavid Peterbefore adoption6db82cd
lines 481–483why, one step back481}482483#[test]Fix typo in unit test.Sendhil Panchadsarambefore adoption8c2ef10
line 484why, one step back484fn test_parameter_scan_commands_names() {Refactor command.rsDavid Peterbefore adoption833529f
lines 485–486why, one step back485 let commands = Commands::build_parameter_scan_commands(486 "val",Split range into range_step and commandsDavid Peterbefore adoption6db82cd
lines 487–503why, one step back487 1i32,488 3i32,489 1i32,490 vec!["name-{val}"],491 vec!["echo {val}"],492 )493 .unwrap();494 assert_eq!(commands.len(), 3);495 let command_names = commands496 .iter()497 .map(|c| c.get_name())498 .collect::<Vec<String>>();499 assert_eq!(command_names, vec!["name-1", "name-2", "name-3"]);500}501502#[test]503fn test_get_specified_command_names() {Refactor command.rsDavid Peterbefore adoption833529f
lines 504–505why, one step back504 let commands = Commands::build_parameter_scan_commands(505 "val",Split range into range_step and commandsDavid Peterbefore adoption6db82cd
lines 506–522why, one step back506 1i32,507 3i32,508 1i32,509 vec!["name-a", "name-b", "name-c"],510 vec!["echo {val}"],511 )512 .unwrap();513 assert_eq!(commands.len(), 3);514 let command_names = commands515 .iter()516 .map(|c| c.get_name())517 .collect::<Vec<String>>();518 assert_eq!(command_names, vec!["name-a", "name-b", "name-c"]);519}520521#[test]522fn test_different_command_name_count_with_parameters() {Refactor command.rsDavid Peterbefore adoption833529f
lines 523–524why, one step back523 let result = Commands::build_parameter_scan_commands(524 "val",Split range into range_step and commandsDavid Peterbefore adoption6db82cd
lines 525–530why, one step back525 1i32,526 3i32,527 1i32,528 vec!["name-1", "name-2"],529 vec!["echo {val}"],530 );Refactor command.rsDavid Peterbefore adoption833529f
lines 531–534why, one step back531 assert!(matches!(532 result.unwrap_err(),533 ParameterScanError::UnexpectedCommandNameCount(2, 3)534 ));Bump rust_decimal from 1.17.0 to 1.19.0dependabot[bot]before adoptioncb33468
line 535why, one step back535}