Skip to content

Commit

Permalink
Merge pull request #264 from dbanty/main
Browse files Browse the repository at this point in the history
fix: Respect Assert::normalize_paths when running subset_matches
  • Loading branch information
epage authored Feb 27, 2024
2 parents 4231148 + 614c1df commit 50010a9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions crates/snapbox/src/assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ impl Assert {
expected_root,
actual_root,
&self.substitutions,
self.normalize_paths,
)
.collect();
self.verify(checks);
Expand Down
10 changes: 7 additions & 3 deletions crates/snapbox/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub use crate::current_rs;

#[cfg(feature = "path")]
use crate::data::{NormalizeMatches, NormalizeNewlines, NormalizePaths};

/// Working directory for tests
#[derive(Debug)]
pub struct PathFixture(PathFixtureInner);
Expand Down Expand Up @@ -221,14 +222,15 @@ impl PathDiff {
) -> impl Iterator<Item = Result<(std::path::PathBuf, std::path::PathBuf), Self>> + '_ {
let pattern_root = pattern_root.into();
let actual_root = actual_root.into();
Self::subset_matches_iter_inner(pattern_root, actual_root, substitutions)
Self::subset_matches_iter_inner(pattern_root, actual_root, substitutions, true)
}

#[cfg(feature = "path")]
pub(crate) fn subset_matches_iter_inner(
expected_root: std::path::PathBuf,
actual_root: std::path::PathBuf,
substitutions: &crate::Substitutions,
normalize_paths: bool,
) -> impl Iterator<Item = Result<(std::path::PathBuf, std::path::PathBuf), Self>> + '_ {
let walker = Walk::new(&expected_root);
walker.map(move |r| {
Expand Down Expand Up @@ -267,9 +269,11 @@ impl PathDiff {
let expected =
crate::Data::read_from(&expected_path, None).normalize(NormalizeNewlines);

actual = actual.coerce_to(expected.intended_format());
if normalize_paths {
actual = actual.normalize(NormalizePaths);
}
actual = actual
.coerce_to(expected.intended_format())
.normalize(NormalizePaths)
.normalize(NormalizeNewlines)
.normalize(NormalizeMatches::new(substitutions, &expected));

Expand Down

0 comments on commit 50010a9

Please sign in to comment.