Skip to content

Commit

Permalink
Fix workspace with default root, simplify lots walkers & metadata (#532)
Browse files Browse the repository at this point in the history
  • Loading branch information
max-sixty authored Aug 8, 2024
1 parent 4fe546d commit d88ca89
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 196 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to insta and cargo-insta are documented here.

## 1.40.0

- `cargo-insta` no longer panics when running `cargo test --accept --workspace`
on a workspace with a default crate. #532

- MSRV for `insta` has been raised to 1.60, and for `cargo-insta` to 1.64.

- Added support for compact debug snapshots (`assert_compact_debug_snapshot`). #514
Expand Down
35 changes: 2 additions & 33 deletions cargo-insta/src/cargo.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::error::Error;
use std::path::{Path, PathBuf};
use std::path::PathBuf;

pub(crate) use cargo_metadata::{Metadata, Package};
pub(crate) use cargo_metadata::Package;

pub(crate) fn find_snapshot_roots(package: &Package) -> Vec<PathBuf> {
let mut roots = Vec::new();
Expand Down Expand Up @@ -44,33 +43,3 @@ pub(crate) fn find_snapshot_roots(package: &Package) -> Vec<PathBuf> {

reduced_roots
}

pub(crate) fn get_metadata(
manifest_path: Option<&Path>,
all: bool,
) -> Result<Metadata, Box<dyn Error>> {
let mut cmd = cargo_metadata::MetadataCommand::new();
if let Some(manifest_path) = manifest_path {
cmd.manifest_path(manifest_path);
}
if all {
cmd.no_deps();
}
let mut metadata = cmd.exec()?;
let Metadata {
packages,
workspace_members,
resolve,
..
} = &mut metadata;
match resolve
.as_ref()
.and_then(|cargo_metadata::Resolve { root, .. }| root.as_ref())
{
Some(root) => packages.retain(|Package { id, .. }| id == root),
None => {
packages.retain(|Package { id, .. }| workspace_members.contains(id));
}
}
Ok(metadata)
}
Loading

0 comments on commit d88ca89

Please sign in to comment.