Skip to content

Commit

Permalink
Added multi --package support
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Nov 16, 2023
1 parent bbdf17f commit d10442a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to insta and cargo-insta are documented here.

## 1.35.0

- The `--package` parameter can be supplied multiple times now. (#427)

## 1.34.0

- Snapshots are now sorted in the UI on review. (#413)
Expand Down
10 changes: 5 additions & 5 deletions cargo-insta/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ struct TestCommand {
tests: bool,
/// Package to run tests for
#[structopt(short = "p", long)]
package: Option<String>,
package: Vec<String>,
/// Exclude packages from the test
#[structopt(long, value_name = "SPEC")]
exclude: Option<String>,
Expand Down Expand Up @@ -643,7 +643,7 @@ fn test_run(mut cmd: TestCommand, color: &str) -> Result<(), Box<dyn Error>> {

// handle unreferenced snapshots if we were instructed to do so
if let Some(ref path) = snapshot_ref_file {
handle_unreferenced_snapshots(path.borrow(), &loc, unreferenced, cmd.package.as_deref())?;
handle_unreferenced_snapshots(path.borrow(), &loc, unreferenced, &cmd.package[..])?;
}

if cmd.review || cmd.accept {
Expand Down Expand Up @@ -688,7 +688,7 @@ fn handle_unreferenced_snapshots(
path: &Path,
loc: &LocationInfo<'_>,
unreferenced: UnreferencedSnapshots,
package: Option<&str>,
packages: &[String],
) -> Result<(), Box<dyn Error>> {
enum Action {
Delete,
Expand Down Expand Up @@ -729,7 +729,7 @@ fn handle_unreferenced_snapshots(
}

let mut encountered_any = false;
for entry in make_deletion_walker(&loc.workspace_root, loc.packages.as_deref(), package) {
for entry in make_deletion_walker(&loc.workspace_root, loc.packages.as_deref(), packages) {
let rel_path = match entry {
Ok(ref entry) => entry.path(),
_ => continue,
Expand Down Expand Up @@ -852,7 +852,7 @@ fn prepare_test_runner<'snapshot_ref>(
proc.arg("--tests");
prevents_doc_run = true;
}
if let Some(ref pkg) = cmd.package {
for pkg in &cmd.package {
proc.arg("--package");
proc.arg(pkg);
}
Expand Down
8 changes: 3 additions & 5 deletions cargo-insta/src/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,15 @@ pub(crate) fn make_snapshot_walker(path: &Path, extensions: &[&str], flags: Find
pub(crate) fn make_deletion_walker(
workspace_root: &Path,
known_packages: Option<&[Package]>,
selected_package: Option<&str>,
selected_packages: &[String],
) -> Walk {
let roots: HashSet<_> = if let Some(packages) = known_packages {
packages
.iter()
.filter_map(|x| {
// filter out packages we did not ask for.
if let Some(only_package) = selected_package {
if x.name != only_package {
return None;
}
if !selected_packages.is_empty() && !selected_packages.contains(&x.name) {
return None;
}
x.manifest_path.parent().unwrap().canonicalize().ok()
})
Expand Down

0 comments on commit d10442a

Please sign in to comment.