Skip to content
Myr

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 file

Take it

The walk stopped after 200 commits: lines older than 017d55a point at it.

Add --setup (-s) option, like --prepare but runs once per batchÆvar Arnfjörð Bjarmasonbefore adoption017d55a

lines 1–2why, one step back
1use std::collections::BTreeMap;
2use std::fmt;

Split range into range_step and commandsDavid Peterbefore adoption6db82cd

line 3why, one step back
3use std::str::FromStr;

Add --setup (-s) option, like --prepare but runs once per batchÆvar Arnfjörð Bjarmasonbefore adoption017d55a

line 4why, one step back
4

Split range into range_step and commandsDavid Peterbefore adoption6db82cd

lines 5–6why, one step back
5use crate::{
6 error::{OptionsError, ParameterScanError},

Move functions into SchedulerDavid Peterbefore adoption39c7736

lines 7–10why, one step back
7 parameter::{
8 range_step::{Numeric, RangeStep},9 ParameterNameAndValue,10 },

Split range into range_step and commandsDavid Peterbefore adoption6db82cd

line 11why, one step back
11};

Move build_commandsDavid Peterbefore adoptioncd38e9c

lines 12–14why, one step back
12
13use clap::ArgMatches;14

New parameter moduleDavid Peterbefore adoption47091a5

lines 15–16why, one step back
15use crate::parameter::tokenize::tokenize;
16use crate::parameter::ParameterValue;

Add --setup (-s) option, like --prepare but runs once per batchÆvar Arnfjörð Bjarmasonbefore adoption017d55a

line 17why, one step back
17

Use raw executor by default, skip intermediate shellDavid Peterbefore adoptiond9418e0

line 18why, one step back
18use anyhow::{bail, Context, Result};

Split range into range_step and commandsDavid Peterbefore adoption6db82cd

lines 19–20why, one step back
19use clap::Values;
20use rust_decimal::Decimal;

Move build_commandsDavid Peterbefore adoptioncd38e9c

line 21why, one step back
21

Add --setup (-s) option, like --prepare but runs once per batchÆvar Arnfjörð Bjarmasonbefore adoption017d55a

lines 22–31why, one step back
22/// 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 back
32 parameters: Vec<ParameterNameAndValue<'a>>,

Add --setup (-s) option, like --prepare but runs once per batchÆvar Arnfjörð Bjarmasonbefore adoption017d55a

lines 33–46why, one step back
33}
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 back
47 parameters: impl IntoIterator<Item = ParameterNameAndValue<'a>>,

Add --setup (-s) option, like --prepare but runs once per batchÆvar Arnfjörð Bjarmasonbefore adoption017d55a

lines 48–51why, one step back
48 ) -> Command<'a> {
49 Command {50 name,51 expression,

Move functions into SchedulerDavid Peterbefore adoption39c7736

line 52why, one step back
52 parameters: parameters.into_iter().collect(),

Add --setup (-s) option, like --prepare but runs once per batchÆvar Arnfjörð Bjarmasonbefore adoption017d55a

lines 53–57why, one step back
53 }
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 back
58 || self.get_command_line(),

Add --setup (-s) option, like --prepare but runs once per batchÆvar Arnfjörð Bjarmasonbefore adoption017d55a

lines 59–62why, one step back
59 |name| self.replace_parameters_in(name),
60 )61 }62

Rename to get_command_lineDavid Peterbefore adoption826449b

line 63why, one step back
63 pub fn get_command_line(&self) -> String {

Add --setup (-s) option, like --prepare but runs once per batchÆvar Arnfjörð Bjarmasonbefore adoption017d55a

line 64why, one step back
64 self.replace_parameters_in(self.expression)

Use raw executor by default, skip intermediate shellDavid Peterbefore adoptiond9418e0

lines 65–79why, one step back
65 }
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 }

Add --setup (-s) option, like --prepare but runs once per batchÆvar Arnfjörð Bjarmasonbefore adoption017d55a

lines 80–81why, one step back
80 }
81

Move functions into SchedulerDavid Peterbefore adoption39c7736

line 82why, one step back
82 pub fn get_parameters(&self) -> &[(&'a str, ParameterValue)] {

Add --setup (-s) option, like --prepare but runs once per batchÆvar Arnfjörð Bjarmasonbefore adoption017d55a

lines 83–99why, one step back
83 &self.parameters
84 }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 back
100 // should not ever run 'echo baz baz'. See `test_get_command_line_nonoverlapping`.

Add --setup (-s) option, like --prepare but runs once per batchÆvar Arnfjörð Bjarmasonbefore adoption017d55a

lines 101–115why, one step back
101 '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}115

Refactor command.rsDavid Peterbefore adoption833529f

line 116why, one step back
116/// A collection of commands that should be benchmarked

Introduce Commands structDavid Peterbefore adoptiona6baf49

line 117why, one step back
117pub struct Commands<'a>(Vec<Command<'a>>);

Move build_commandsDavid Peterbefore adoptioncd38e9c

line 118why, one step back
118

Introduce Commands structDavid Peterbefore adoptiona6baf49

lines 119–125why, one step back
119impl<'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 back
126 Ok(Self(Self::get_parameter_scan_commands(

Introduce Commands structDavid Peterbefore adoptiona6baf49

lines 127–145why, one step back
127 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 back
146 Self::find_duplicates(param_names_and_values.iter().map(|(name, _)| *name));

Introduce Commands structDavid Peterbefore adoptiona6baf49

lines 147–149why, one step back
147 if !duplicates.is_empty() {
148 bail!("Duplicate parameter names: {}", &duplicates.join(", "));149 }

Move build_commandsDavid Peterbefore adoptioncd38e9c

line 150why, one step back
150 }

Introduce Commands structDavid Peterbefore adoptiona6baf49

line 151why, one step back
151 let command_list = command_strings.collect::<Vec<&str>>();

Move build_commandsDavid Peterbefore adoptioncd38e9c

line 152why, one step back
152

Introduce Commands structDavid Peterbefore adoptiona6baf49

lines 153–163why, one step back
153 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 back
164

Introduce Commands structDavid Peterbefore adoptiona6baf49

lines 165–174why, one step back
165 // `--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 back
175

Introduce Commands structDavid Peterbefore adoptiona6baf49

lines 176–184why, one step back
176 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 back
185

Introduce Commands structDavid Peterbefore adoptiona6baf49

line 186why, one step back
186 let (command_index, params_indices) = index.split_first().unwrap();

Move functions into SchedulerDavid Peterbefore adoption39c7736

line 187why, one step back
187 let parameters: Vec<_> = param_names_and_values

Introduce Commands structDavid Peterbefore adoptiona6baf49

lines 188–196why, one step back
188 .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 back
197

Introduce Commands structDavid Peterbefore adoptiona6baf49

lines 198–205why, one step back
198 // 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 back
206 }

Introduce Commands structDavid Peterbefore adoptiona6baf49

line 207why, one step back
207 break 'outer;

Move build_commandsDavid Peterbefore adoptioncd38e9c

lines 208–209why, one step back
208 }
209

Introduce Commands structDavid Peterbefore adoptiona6baf49

lines 210–215why, one step back
210 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 back
216

Introduce Commands structDavid Peterbefore adoptiona6baf49

lines 217–222why, one step back
217 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 back
223 }
224 }225

Introduce Commands structDavid Peterbefore adoptiona6baf49

lines 226–227why, one step back
226 pub fn iter(&self) -> impl Iterator<Item = &Command<'a>> {
227 self.0.iter()

Move build_commandsDavid Peterbefore adoptioncd38e9c

line 228why, one step back
228 }

Introduce Commands structDavid Peterbefore adoptiona6baf49

line 229why, one step back
229

Fix clippy warningDavid Peterbefore adoption250db61

line 230why, one step back
230 pub fn num_commands(&self) -> usize {

Introduce Commands structDavid Peterbefore adoptiona6baf49

lines 231–232why, one step back
231 self.0.len()
232 }

Refactor command.rsDavid Peterbefore adoption833529f

lines 233–332why, one step back
233
234 /// 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 back
333}
334

Add --setup (-s) option, like --prepare but runs once per batchÆvar Arnfjörð Bjarmasonbefore adoption017d55a

line 335why, one step back
335#[test]

Rename to get_command_lineDavid Peterbefore adoption826449b

line 336why, one step back
336fn test_get_command_line_nonoverlapping() {

Add --setup (-s) option, like --prepare but runs once per batchÆvar Arnfjörð Bjarmasonbefore adoption017d55a

lines 337–344why, one step back
337 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 back
345 assert_eq!(cmd.get_command_line(), "echo {bar} baz quux");

Add --setup (-s) option, like --prepare but runs once per batchÆvar Arnfjörð Bjarmasonbefore adoption017d55a

lines 346–362why, one step back
346}
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 back
363 write!(f, "{}", self.get_command_line())

Add --setup (-s) option, like --prepare but runs once per batchÆvar Arnfjörð Bjarmasonbefore adoption017d55a

line 364why, one step back
364 }

Move build_commandsDavid Peterbefore adoptioncd38e9c

lines 365–368why, one step back
365}
366367#[test]368fn test_build_commands_cross_product() {

Update dependenciesDavid Peterbefore adoptionf2f1dd9

line 369why, one step back
369 use crate::cli::get_cli_arguments;

Move build_commandsDavid Peterbefore adoptioncd38e9c

line 370why, one step back
370

Introduce Commands structDavid Peterbefore adoptiona6baf49

line 371why, one step back
371 let matches = get_cli_arguments(vec![

Move build_commandsDavid Peterbefore adoptioncd38e9c

lines 372–381why, one step back
372 "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 back
382 let result = Commands::from_cli_arguments(&matches).unwrap().0;

Move build_commandsDavid Peterbefore adoptioncd38e9c

lines 383–406why, one step back
383
384 // 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 back
407 use crate::cli::get_cli_arguments;

Move build_commandsDavid Peterbefore adoptioncd38e9c

line 408why, one step back
408

Introduce Commands structDavid Peterbefore adoptiona6baf49

line 409why, one step back
409 let matches = get_cli_arguments(vec![

Move build_commandsDavid Peterbefore adoptioncd38e9c

lines 410–417why, one step back
410 "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 back
418 let commands = Commands::from_cli_arguments(&matches).unwrap().0;

Move build_commandsDavid Peterbefore adoptioncd38e9c

lines 419–421why, one step back
419 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 back
422 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 back
424}
425426#[test]

Refactor command.rsDavid Peterbefore adoption833529f

line 427why, one step back
427fn test_build_parameter_scan_commands() {

Update dependenciesDavid Peterbefore adoptionf2f1dd9

line 428why, one step back
428 use crate::cli::get_cli_arguments;

Introduce Commands structDavid Peterbefore adoptiona6baf49

line 429why, one step back
429 let matches = get_cli_arguments(vec![

Move build_commandsDavid Peterbefore adoptioncd38e9c

lines 430–440why, one step back
430 "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 back
441 let commands = Commands::from_cli_arguments(&matches).unwrap().0;

Move build_commandsDavid Peterbefore adoptioncd38e9c

lines 442–444why, one step back
442 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 back
445 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 back
447}
448449#[test]

Refactor command.rsDavid Peterbefore adoption833529f

lines 450–459why, one step back
450fn 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 back
460 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 back
462 assert_eq!(commands[2].get_command_line(), "echo 7");

Split range into range_step and commandsDavid Peterbefore adoption6db82cd

lines 463–465why, one step back
463}
464465#[test]

Refactor command.rsDavid Peterbefore adoption833529f

line 466why, one step back
466fn test_parameter_scan_commands_decimal() {

Split range into range_step and commandsDavid Peterbefore adoption6db82cd

lines 467–470why, one step back
467 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();470

Refactor command.rsDavid Peterbefore adoption833529f

lines 471–472why, one step back
471 let commands = Commands::build_parameter_scan_commands(
472 "val",

Split range into range_step and commandsDavid Peterbefore adoption6db82cd

lines 473–481why, one step back
473 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 back
482 assert_eq!(commands[3].get_command_line(), "echo 0.99");

Split range into range_step and commandsDavid Peterbefore adoption6db82cd

lines 483–485why, one step back
483}
484485#[test]

Refactor command.rsDavid Peterbefore adoption833529f

lines 486–488why, one step back
486fn 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 back
489 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 back
506 let commands = Commands::build_parameter_scan_commands(
507 "val",

Split range into range_step and commandsDavid Peterbefore adoption6db82cd

lines 508–524why, one step back
508 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 back
525 let result = Commands::build_parameter_scan_commands(
526 "val",

Split range into range_step and commandsDavid Peterbefore adoption6db82cd

lines 527–532why, one step back
527 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 back
533 assert!(matches!(
534 result.unwrap_err(),535 ParameterScanError::UnexpectedCommandNameCount(2, 3)536 ));

Add --setup (-s) option, like --prepare but runs once per batchÆvar Arnfjörð Bjarmasonbefore adoption017d55a

line 537why, one step back
537}