Skip to content

Commit

Permalink
ptest: Add --test argument
Browse files Browse the repository at this point in the history
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 <david.brown@linaro.org>
  • Loading branch information
d3zd3z committed Apr 19, 2024
1 parent 67fc1fc commit 0ceb85a
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions ptest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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<usize>,

#[command(subcommand)]
command: Commands,
}
Expand Down Expand Up @@ -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<usize> = 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 {
Expand Down

0 comments on commit 0ceb85a

Please sign in to comment.