diff --git a/src/snapshots/cargo_mutants__visit__test__expected_mutants_for_own_source_tree.snap b/src/snapshots/cargo_mutants__visit__test__expected_mutants_for_own_source_tree.snap index 29b73f5d..efa3fa9b 100644 --- a/src/snapshots/cargo_mutants__visit__test__expected_mutants_for_own_source_tree.snap +++ b/src/snapshots/cargo_mutants__visit__test__expected_mutants_for_own_source_tree.snap @@ -328,6 +328,8 @@ src/visit.rs: replace attr_is_mutants_skip -> bool with false src/workspace.rs: replace ::fmt -> fmt::Result with Ok(Default::default()) src/workspace.rs: replace ::fmt -> fmt::Result with Err(::anyhow::anyhow!("mutated!")) src/workspace.rs: replace PackageFilter::explicit -> PackageFilter with Default::default() +src/workspace.rs: replace PackageFilter::matches -> bool with true +src/workspace.rs: replace PackageFilter::matches -> bool with false src/workspace.rs: replace Workspace::open -> Result with Ok(Default::default()) src/workspace.rs: replace Workspace::open -> Result with Err(::anyhow::anyhow!("mutated!")) src/workspace.rs: replace Workspace::packages -> Result>> with Ok(vec![]) @@ -344,8 +346,6 @@ src/workspace.rs: replace Workspace::discover -> Result with Err(::a src/workspace.rs: replace Workspace::mutants -> Result> with Ok(vec![]) src/workspace.rs: replace Workspace::mutants -> Result> with Ok(vec![Default::default()]) src/workspace.rs: replace Workspace::mutants -> Result> with Err(::anyhow::anyhow!("mutated!")) -src/workspace.rs: replace filter_package_metadata -> Vec<&'m cargo_metadata::Package> with vec![] -src/workspace.rs: replace filter_package_metadata -> Vec<&'m cargo_metadata::Package> with vec![&Default::default()] src/workspace.rs: replace direct_package_sources -> Result> with Ok(vec![]) src/workspace.rs: replace direct_package_sources -> Result> with Ok(vec![Default::default()]) src/workspace.rs: replace direct_package_sources -> Result> with Err(::anyhow::anyhow!("mutated!")) diff --git a/src/workspace.rs b/src/workspace.rs index 174b50d8..af8adfef 100644 --- a/src/workspace.rs +++ b/src/workspace.rs @@ -44,6 +44,16 @@ impl PackageFilter { pub fn explicit>(names: I) -> PackageFilter { PackageFilter::Explicit(names.into_iter().map(|s| s.to_string()).collect_vec()) } + + pub fn matches(&self, package_metadata: &cargo_metadata::Package) -> bool { + match self { + PackageFilter::All => true, + PackageFilter::Explicit(include_names) => { + include_names.contains(&package_metadata.name) + } + PackageFilter::Auto(..) => todo!(), + } + } } /// A package and the top source files within it. @@ -77,8 +87,11 @@ impl Workspace { /// Find all the packages and their top source files. fn package_tops(&self, package_filter: &PackageFilter) -> Result> { let mut tops = Vec::new(); - for package_metadata in filter_package_metadata(&self.metadata, package_filter) + for package_metadata in self + .metadata + .workspace_packages() .into_iter() + .filter(|pmeta| package_filter.matches(pmeta)) .sorted_by_key(|p| &p.name) { check_interrupted()?; @@ -160,23 +173,6 @@ impl Workspace { } } -fn filter_package_metadata<'m>( - metadata: &'m cargo_metadata::Metadata, - package_filter: &PackageFilter, -) -> Vec<&'m cargo_metadata::Package> { - metadata - .workspace_packages() - .iter() - .filter(move |pmeta| match package_filter { - PackageFilter::All => true, - PackageFilter::Explicit(include_names) => include_names.contains(&pmeta.name), - PackageFilter::Auto(..) => todo!(), - }) - .sorted_by_key(|pm| &pm.name) - .copied() - .collect() -} - /// Find all the files that are named in the `path` of targets in a Cargo manifest that should be tested. /// /// These are the starting points for discovering source files.