command.rs
This file
Path
src/command.rs
547 lines · 17.1 KiB · Rust
Last changed by
chore: run fmtBenjamin Rombautbefore adoptionfcaa6d3
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 back12chore: run fmtBenjamin Rombautbefore adoptionfcaa6d3
line 13why, one step back13use clap::{parser::ValuesRef, ArgMatches};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
line 120why, one step back120 let command_names = matches.get_many::<String>("command-name");chore: run fmtBenjamin Rombautbefore adoptionfcaa6d3
lines 121–125why, one step back121 let command_strings = matches122 .get_many::<String>("command")123 .unwrap_or_default()124 .map(|v| v.as_str())125 .collect::<Vec<_>>();Introduce Commands structDavid Peterbefore adoptiona6baf49
line 126why, one step back126update to clap 4Benjamin Rombautbefore adoption8d38ef3
line 127why, one step back127 if let Some(args) = matches.get_many::<String>("parameter-scan") {chore: run fmtBenjamin Rombautbefore adoptionfcaa6d3
lines 128–130why, one step back128 let step_size = matches129 .get_one::<String>("parameter-step-size")130 .map(|s| s.as_str());Refactor command.rsDavid Peterbefore adoption833529f
line 131why, one step back131 Ok(Self(Self::get_parameter_scan_commands(Introduce Commands structDavid Peterbefore adoptiona6baf49
lines 132–136why, one step back132 command_names,133 command_strings,134 args,135 step_size,136 )?))update to clap 4Benjamin Rombautbefore adoption8d38ef3
line 137why, one step back137 } else if let Some(args) = matches.get_many::<String>("parameter-list") {chore: run fmtBenjamin Rombautbefore adoptionfcaa6d3
lines 138–140why, one step back138 let command_names = command_names.map_or(vec![], |names| {139 names.map(|v| v.as_str()).collect::<Vec<_>>()140 });update to clap 4Benjamin Rombautbefore adoption8d38ef3
line 141why, one step back141 let args: Vec<_> = args.map(|v| v.as_str()).collect::<Vec<_>>();Introduce Commands structDavid Peterbefore adoptiona6baf49
lines 142–151why, one step back142 let param_names_and_values: Vec<(&str, Vec<String>)> = args143 .chunks_exact(2)144 .map(|pair| {145 let name = pair[0];146 let list_str = pair[1];147 (name, tokenize(list_str))148 })149 .collect();150 {151 let duplicates =Refactor command.rsDavid Peterbefore adoption833529f
line 152why, one step back152 Self::find_duplicates(param_names_and_values.iter().map(|(name, _)| *name));Introduce Commands structDavid Peterbefore adoptiona6baf49
lines 153–155why, one step back153 if !duplicates.is_empty() {154 bail!("Duplicate parameter names: {}", &duplicates.join(", "));155 }Move build_commandsDavid Peterbefore adoptioncd38e9c
line 156why, one step back156 }update to clap 4Benjamin Rombautbefore adoption8d38ef3
line 157why, one step back157 let command_list = command_strings;Move build_commandsDavid Peterbefore adoptioncd38e9c
line 158why, one step back158Introduce Commands structDavid Peterbefore adoptiona6baf49
lines 159–169why, one step back159 let dimensions: Vec<usize> = std::iter::once(command_list.len())160 .chain(161 param_names_and_values162 .iter()163 .map(|(_, values)| values.len()),164 )165 .collect();166 let param_space_size = dimensions.iter().product();167 if param_space_size == 0 {168 return Ok(Self(Vec::new()));169 }Move build_commandsDavid Peterbefore adoptioncd38e9c
line 170why, one step back170Introduce Commands structDavid Peterbefore adoptiona6baf49
lines 171–180why, one step back171 // `--command-name` should appear exactly once or exactly B times,172 // where B is the total number of benchmarks.173 let command_name_count = command_names.len();174 if command_name_count > 1 && command_name_count != param_space_size {175 return Err(OptionsError::UnexpectedCommandNameCount(176 command_name_count,177 param_space_size,178 )179 .into());180 }Move build_commandsDavid Peterbefore adoptioncd38e9c
line 181why, one step back181Introduce Commands structDavid Peterbefore adoptiona6baf49
lines 182–187why, one step back182 let mut i = 0;183 let mut commands = Vec::with_capacity(param_space_size);184 let mut index = vec![0usize; dimensions.len()];185 'outer: loop {186 let name = command_names187 .get(i)Fix clippy suggestionsDavid Peterbefore adoptionc7e5694
line 188why, one step back188 .or_else(|| command_names.first())Introduce Commands structDavid Peterbefore adoptiona6baf49
lines 189–190why, one step back189 .copied();190 i += 1;Move build_commandsDavid Peterbefore adoptioncd38e9c
line 191why, one step back191Introduce Commands structDavid Peterbefore adoptiona6baf49
line 192why, one step back192 let (command_index, params_indices) = index.split_first().unwrap();Move functions into SchedulerDavid Peterbefore adoption39c7736
line 193why, one step back193 let parameters: Vec<_> = param_names_and_valuesIntroduce Commands structDavid Peterbefore adoptiona6baf49
lines 194–202why, one step back194 .iter()195 .zip(params_indices)196 .map(|((name, values), i)| (*name, ParameterValue::Text(values[*i].clone())))197 .collect();198 commands.push(Command::new_parametrized(199 name,200 command_list[*command_index],201 parameters,202 ));Move build_commandsDavid Peterbefore adoptioncd38e9c
line 203why, one step back203Introduce Commands structDavid Peterbefore adoptiona6baf49
lines 204–211why, one step back204 // Increment index, exiting loop on overflow.205 for (i, n) in index.iter_mut().zip(dimensions.iter()) {206 *i += 1;207 if *i < *n {208 continue 'outer;209 } else {210 *i = 0;211 }Move build_commandsDavid Peterbefore adoptioncd38e9c
line 212why, one step back212 }Introduce Commands structDavid Peterbefore adoptiona6baf49
line 213why, one step back213 break 'outer;Move build_commandsDavid Peterbefore adoptioncd38e9c
lines 214–215why, one step back214 }215Introduce Commands structDavid Peterbefore adoptiona6baf49
lines 216–217why, one step back216 Ok(Self(commands))217 } else {chore: run fmtBenjamin Rombautbefore adoptionfcaa6d3
lines 218–220why, one step back218 let command_names = command_names.map_or(vec![], |names| {219 names.map(|v| v.as_str()).collect::<Vec<_>>()220 });Introduce Commands structDavid Peterbefore adoptiona6baf49
lines 221–223why, one step back221 if command_names.len() > command_strings.len() {222 return Err(OptionsError::TooManyCommandNames(command_strings.len()).into());223 }Move build_commandsDavid Peterbefore adoptioncd38e9c
line 224why, one step back224update to clap 4Benjamin Rombautbefore adoption8d38ef3
line 225why, one step back225 let command_list = command_strings;Introduce Commands structDavid Peterbefore adoptiona6baf49
lines 226–230why, one step back226 let mut commands = Vec::with_capacity(command_list.len());227 for (i, s) in command_list.iter().enumerate() {228 commands.push(Command::new(command_names.get(i).copied(), s));229 }230 Ok(Self(commands))Move build_commandsDavid Peterbefore adoptioncd38e9c
lines 231–233why, one step back231 }232 }233Introduce Commands structDavid Peterbefore adoptiona6baf49
lines 234–235why, one step back234 pub fn iter(&self) -> impl Iterator<Item = &Command<'a>> {235 self.0.iter()Move build_commandsDavid Peterbefore adoptioncd38e9c
line 236why, one step back236 }Introduce Commands structDavid Peterbefore adoptiona6baf49
line 237why, one step back237Fix clippy warningDavid Peterbefore adoption250db61
line 238why, one step back238 pub fn num_commands(&self) -> usize {Introduce Commands structDavid Peterbefore adoptiona6baf49
lines 239–240why, one step back239 self.0.len()240 }Refactor command.rsDavid Peterbefore adoption833529f
lines 241–281why, one step back241242 /// Finds all the strings that appear multiple times in the input iterator, returning them in243 /// sorted order. If no string appears more than once, the result is an empty vector.244 fn find_duplicates<'b, I: IntoIterator<Item = &'b str>>(i: I) -> Vec<&'b str> {245 let mut counts = BTreeMap::<&'b str, usize>::new();246 for s in i {247 *counts.entry(s).or_default() += 1;248 }249 counts250 .into_iter()251 .filter_map(|(k, n)| if n > 1 { Some(k) } else { None })252 .collect()253 }254255 fn build_parameter_scan_commands<'b, T: Numeric>(256 param_name: &'b str,257 param_min: T,258 param_max: T,259 step: T,260 command_names: Vec<&'b str>,261 command_strings: Vec<&'b str>,262 ) -> Result<Vec<Command<'b>>, ParameterScanError> {263 let param_range = RangeStep::new(param_min, param_max, step)?;264 let param_count = param_range.size_hint().1.unwrap();265 let command_name_count = command_names.len();266267 // `--command-name` should appear exactly once or exactly B times,268 // where B is the total number of benchmarks.269 if command_name_count > 1 && command_name_count != param_count {270 return Err(ParameterScanError::UnexpectedCommandNameCount(271 command_name_count,272 param_count,273 ));274 }275276 let mut i = 0;277 let mut commands = vec![];278 for value in param_range {279 for cmd in &command_strings {280 let name = command_names281 .get(i)Fix clippy suggestionsDavid Peterbefore adoptionc7e5694
line 282why, one step back282 .or_else(|| command_names.first())Refactor command.rsDavid Peterbefore adoption833529f
lines 283–295why, one step back283 .copied();284 commands.push(Command::new_parametrized(285 name,286 cmd,287 vec![(param_name, ParameterValue::Numeric(value.into()))],288 ));289 i += 1;290 }291 }292 Ok(commands)293 }294295 fn get_parameter_scan_commands<'b>(update to clap 4Benjamin Rombautbefore adoption8d38ef3
lines 296–298why, one step back296 command_names: Option<ValuesRef<'b, String>>,297 command_strings: Vec<&'b str>,298 mut vals: ValuesRef<'b, String>,Refactor command.rsDavid Peterbefore adoption833529f
lines 299–300why, one step back299 step: Option<&str>,300 ) -> Result<Vec<Command<'b>>, ParameterScanError> {chore: run fmtBenjamin Rombautbefore adoptionfcaa6d3
lines 301–303why, one step back301 let command_names = command_names.map_or(vec![], |names| {302 names.map(|v| v.as_str()).collect::<Vec<_>>()303 });update to clap 4Benjamin Rombautbefore adoption8d38ef3
lines 304–307why, one step back304 let command_strings = command_strings;305 let param_name = vals.next().unwrap().as_str();306 let param_min = vals.next().unwrap().as_str();307 let param_max = vals.next().unwrap().as_str();Refactor command.rsDavid Peterbefore adoption833529f
lines 308–342why, one step back308309 // attempt to parse as integers310 if let (Ok(param_min), Ok(param_max), Ok(step)) = (311 param_min.parse::<i32>(),312 param_max.parse::<i32>(),313 step.unwrap_or("1").parse::<i32>(),314 ) {315 return Self::build_parameter_scan_commands(316 param_name,317 param_min,318 param_max,319 step,320 command_names,321 command_strings,322 );323 }324325 // try parsing them as decimals326 let param_min = Decimal::from_str(param_min)?;327 let param_max = Decimal::from_str(param_max)?;328329 if step.is_none() {330 return Err(ParameterScanError::StepRequired);331 }332333 let step = Decimal::from_str(step.unwrap())?;334 Self::build_parameter_scan_commands(335 param_name,336 param_min,337 param_max,338 step,339 command_names,340 command_strings,341 )342 }Move build_commandsDavid Peterbefore adoptioncd38e9c
lines 343–344why, one step back343}344Bump rust_decimal from 1.17.0 to 1.19.0dependabot[bot]before adoptioncb33468
line 345why, one step back345#[test]Rename to get_command_lineDavid Peterbefore adoption826449b
line 346why, one step back346fn test_get_command_line_nonoverlapping() {Bump rust_decimal from 1.17.0 to 1.19.0dependabot[bot]before adoptioncb33468
lines 347–354why, one step back347 let cmd = Command::new_parametrized(348 None,349 "echo {foo} {bar}",350 vec![351 ("foo", ParameterValue::Text("{bar} baz".into())),352 ("bar", ParameterValue::Text("quux".into())),353 ],354 );Rename to get_command_lineDavid Peterbefore adoption826449b
line 355why, one step back355 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 356–372why, one step back356}357358#[test]359fn test_get_parameterized_command_name() {360 let cmd = Command::new_parametrized(361 Some("name-{bar}-{foo}"),362 "echo {foo} {bar}",363 vec![364 ("foo", ParameterValue::Text("baz".into())),365 ("bar", ParameterValue::Text("quux".into())),366 ],367 );368 assert_eq!(cmd.get_name(), "name-quux-baz");369}370371impl<'a> fmt::Display for Command<'a> {372 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {Rename to get_command_lineDavid Peterbefore adoption826449b
line 373why, one step back373 write!(f, "{}", self.get_command_line())Bump rust_decimal from 1.17.0 to 1.19.0dependabot[bot]before adoptioncb33468
line 374why, one step back374 }Move build_commandsDavid Peterbefore adoptioncd38e9c
lines 375–378why, one step back375}376377#[test]378fn test_build_commands_cross_product() {Update dependenciesDavid Peterbefore adoptionf2f1dd9
line 379why, one step back379 use crate::cli::get_cli_arguments;Move build_commandsDavid Peterbefore adoptioncd38e9c
line 380why, one step back380Introduce Commands structDavid Peterbefore adoptiona6baf49
line 381why, one step back381 let matches = get_cli_arguments(vec![Move build_commandsDavid Peterbefore adoptioncd38e9c
lines 382–391why, one step back382 "hyperfine",383 "-L",384 "par1",385 "a,b",386 "-L",387 "par2",388 "z,y",389 "echo {par1} {par2}",390 "printf '%s\n' {par1} {par2}",391 ]);Introduce Commands structDavid Peterbefore adoptiona6baf49
line 392why, one step back392 let result = Commands::from_cli_arguments(&matches).unwrap().0;Move build_commandsDavid Peterbefore adoptioncd38e9c
lines 393–416why, one step back393394 // Iteration order: command list first, then parameters in listed order (here, "par1" before395 // "par2", which is distinct from their sorted order), with parameter values in listed order.396 let pv = |s: &str| ParameterValue::Text(s.to_string());397 let cmd = |cmd: usize, par1: &str, par2: &str| {398 let expression = ["echo {par1} {par2}", "printf '%s\n' {par1} {par2}"][cmd];399 let params = vec![("par1", pv(par1)), ("par2", pv(par2))];400 Command::new_parametrized(None, expression, params)401 };402 let expected = vec![403 cmd(0, "a", "z"),404 cmd(1, "a", "z"),405 cmd(0, "b", "z"),406 cmd(1, "b", "z"),407 cmd(0, "a", "y"),408 cmd(1, "a", "y"),409 cmd(0, "b", "y"),410 cmd(1, "b", "y"),411 ];412 assert_eq!(result, expected);413}414415#[test]416fn test_build_parameter_list_commands() {Update dependenciesDavid Peterbefore adoptionf2f1dd9
line 417why, one step back417 use crate::cli::get_cli_arguments;Move build_commandsDavid Peterbefore adoptioncd38e9c
line 418why, one step back418Introduce Commands structDavid Peterbefore adoptiona6baf49
line 419why, one step back419 let matches = get_cli_arguments(vec![Move build_commandsDavid Peterbefore adoptioncd38e9c
lines 420–427why, one step back420 "hyperfine",421 "echo {foo}",422 "--parameter-list",423 "foo",424 "1,2",425 "--command-name",426 "name-{foo}",427 ]);Introduce Commands structDavid Peterbefore adoptiona6baf49
line 428why, one step back428 let commands = Commands::from_cli_arguments(&matches).unwrap().0;Move build_commandsDavid Peterbefore adoptioncd38e9c
lines 429–431why, one step back429 assert_eq!(commands.len(), 2);430 assert_eq!(commands[0].get_name(), "name-1");431 assert_eq!(commands[1].get_name(), "name-2");Rename to get_command_lineDavid Peterbefore adoption826449b
lines 432–433why, one step back432 assert_eq!(commands[0].get_command_line(), "echo 1");433 assert_eq!(commands[1].get_command_line(), "echo 2");Move build_commandsDavid Peterbefore adoptioncd38e9c
lines 434–436why, one step back434}435436#[test]Refactor command.rsDavid Peterbefore adoption833529f
line 437why, one step back437fn test_build_parameter_scan_commands() {Update dependenciesDavid Peterbefore adoptionf2f1dd9
line 438why, one step back438 use crate::cli::get_cli_arguments;Introduce Commands structDavid Peterbefore adoptiona6baf49
line 439why, one step back439 let matches = get_cli_arguments(vec![Move build_commandsDavid Peterbefore adoptioncd38e9c
lines 440–450why, one step back440 "hyperfine",441 "echo {val}",442 "--parameter-scan",443 "val",444 "1",445 "2",446 "--parameter-step-size",447 "1",448 "--command-name",449 "name-{val}",450 ]);Introduce Commands structDavid Peterbefore adoptiona6baf49
line 451why, one step back451 let commands = Commands::from_cli_arguments(&matches).unwrap().0;Move build_commandsDavid Peterbefore adoptioncd38e9c
lines 452–454why, one step back452 assert_eq!(commands.len(), 2);453 assert_eq!(commands[0].get_name(), "name-1");454 assert_eq!(commands[1].get_name(), "name-2");Rename to get_command_lineDavid Peterbefore adoption826449b
lines 455–456why, one step back455 assert_eq!(commands[0].get_command_line(), "echo 1");456 assert_eq!(commands[1].get_command_line(), "echo 2");Split range into range_step and commandsDavid Peterbefore adoption6db82cd
lines 457–459why, one step back457}458459#[test]Refactor command.rsDavid Peterbefore adoption833529f
lines 460–469why, one step back460fn test_parameter_scan_commands_int() {461 let commands = Commands::build_parameter_scan_commands(462 "val",463 1i32,464 7i32,465 3i32,466 vec![],467 vec!["echo {val}"],468 )469 .unwrap();Split range into range_step and commandsDavid Peterbefore adoption6db82cd
lines 470–471why, one step back470 assert_eq!(commands.len(), 3);471 assert_eq!(commands[2].get_name(), "echo 7");Rename to get_command_lineDavid Peterbefore adoption826449b
line 472why, one step back472 assert_eq!(commands[2].get_command_line(), "echo 7");Split range into range_step and commandsDavid Peterbefore adoption6db82cd
lines 473–475why, one step back473}474475#[test]Refactor command.rsDavid Peterbefore adoption833529f
line 476why, one step back476fn test_parameter_scan_commands_decimal() {Split range into range_step and commandsDavid Peterbefore adoption6db82cd
lines 477–480why, one step back477 let param_min = Decimal::from_str("0").unwrap();478 let param_max = Decimal::from_str("1").unwrap();479 let step = Decimal::from_str("0.33").unwrap();480Refactor command.rsDavid Peterbefore adoption833529f
lines 481–482why, one step back481 let commands = Commands::build_parameter_scan_commands(482 "val",Split range into range_step and commandsDavid Peterbefore adoption6db82cd
lines 483–491why, one step back483 param_min,484 param_max,485 step,486 vec![],487 vec!["echo {val}"],488 )489 .unwrap();490 assert_eq!(commands.len(), 4);491 assert_eq!(commands[3].get_name(), "echo 0.99");Rename to get_command_lineDavid Peterbefore adoption826449b
line 492why, one step back492 assert_eq!(commands[3].get_command_line(), "echo 0.99");Split range into range_step and commandsDavid Peterbefore adoption6db82cd
lines 493–495why, one step back493}494495#[test]Fix typo in unit test.Sendhil Panchadsarambefore adoption8c2ef10
line 496why, one step back496fn test_parameter_scan_commands_names() {Refactor command.rsDavid Peterbefore adoption833529f
lines 497–498why, one step back497 let commands = Commands::build_parameter_scan_commands(498 "val",Split range into range_step and commandsDavid Peterbefore adoption6db82cd
lines 499–515why, one step back499 1i32,500 3i32,501 1i32,502 vec!["name-{val}"],503 vec!["echo {val}"],504 )505 .unwrap();506 assert_eq!(commands.len(), 3);507 let command_names = commands508 .iter()509 .map(|c| c.get_name())510 .collect::<Vec<String>>();511 assert_eq!(command_names, vec!["name-1", "name-2", "name-3"]);512}513514#[test]515fn test_get_specified_command_names() {Refactor command.rsDavid Peterbefore adoption833529f
lines 516–517why, one step back516 let commands = Commands::build_parameter_scan_commands(517 "val",Split range into range_step and commandsDavid Peterbefore adoption6db82cd
lines 518–534why, one step back518 1i32,519 3i32,520 1i32,521 vec!["name-a", "name-b", "name-c"],522 vec!["echo {val}"],523 )524 .unwrap();525 assert_eq!(commands.len(), 3);526 let command_names = commands527 .iter()528 .map(|c| c.get_name())529 .collect::<Vec<String>>();530 assert_eq!(command_names, vec!["name-a", "name-b", "name-c"]);531}532533#[test]534fn test_different_command_name_count_with_parameters() {Refactor command.rsDavid Peterbefore adoption833529f
lines 535–536why, one step back535 let result = Commands::build_parameter_scan_commands(536 "val",Split range into range_step and commandsDavid Peterbefore adoption6db82cd
lines 537–542why, one step back537 1i32,538 3i32,539 1i32,540 vec!["name-1", "name-2"],541 vec!["echo {val}"],542 );Refactor command.rsDavid Peterbefore adoption833529f
lines 543–546why, one step back543 assert!(matches!(544 result.unwrap_err(),545 ParameterScanError::UnexpectedCommandNameCount(2, 3)546 ));Bump rust_decimal from 1.17.0 to 1.19.0dependabot[bot]before adoptioncb33468
line 547why, one step back547}