From 0ceb85ad58c56adc63ff89277c95f9af2aa6065f Mon Sep 17 00:00:00 2001 From: David Brown Date: Thu, 11 Apr 2024 09:55:11 -0600 Subject: [PATCH] ptest: Add `--test` argument The `--test` (`-t`) argument allows the caller to limit the tests that are invoked by ptest. The argument can be specified multiple times to run several tests. The numbers are based on the output of `--list`. Signed-off-by: David Brown --- ptest/src/main.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ptest/src/main.rs b/ptest/src/main.rs index e0e41a96..b0d7e66d 100644 --- a/ptest/src/main.rs +++ b/ptest/src/main.rs @@ -48,6 +48,10 @@ fn main() -> Result<()> { let matrix = Matrix::from_yaml(&workflow); + let matrix = if args.test.len() == 0 { matrix } else { + matrix.only(&args.test) + }; + match args.command { Commands::List => { matrix.show(); @@ -96,6 +100,10 @@ struct Cli { #[arg(short, long, default_value = "../.github/workflows/sim.yaml")] workflow: String, + /// The tests to run (defaults to all) + #[arg(short, long)] + test: Vec, + #[command(subcommand)] command: Commands, } @@ -259,6 +267,20 @@ impl Matrix { println!("{:3}. {}", i, feature.simple_textual()); } } + + /// Replace this matrix with one that only has the chosen tests in it. Note + /// that the original order is preserved, not that given in `pick`. + fn only(self, pick: &[usize]) -> Self { + let pick: HashSet = pick.iter().cloned().collect(); + let envs: Vec<_> = self + .envs + .into_iter() + .enumerate() + .filter(|(ind, _)| pick.contains(ind)) + .map(|(_, item)| item) + .collect(); + Matrix { envs } + } } impl FeatureSet {