From 614c1dfe99756cd6dc60c78654b3f09fb4b57dad Mon Sep 17 00:00:00 2001 From: Dylan Anthony Date: Mon, 26 Feb 2024 16:42:51 -0700 Subject: [PATCH] fix: Respect Assert::normalize_paths when running subset_matches --- crates/snapbox/src/assert.rs | 1 + crates/snapbox/src/path.rs | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/snapbox/src/assert.rs b/crates/snapbox/src/assert.rs index 8c7927f0..295fa1e1 100644 --- a/crates/snapbox/src/assert.rs +++ b/crates/snapbox/src/assert.rs @@ -288,6 +288,7 @@ impl Assert { expected_root, actual_root, &self.substitutions, + self.normalize_paths, ) .collect(); self.verify(checks); diff --git a/crates/snapbox/src/path.rs b/crates/snapbox/src/path.rs index b307c1c8..8d5d0919 100644 --- a/crates/snapbox/src/path.rs +++ b/crates/snapbox/src/path.rs @@ -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); @@ -221,7 +222,7 @@ impl PathDiff { ) -> impl Iterator> + '_ { 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")] @@ -229,6 +230,7 @@ impl PathDiff { expected_root: std::path::PathBuf, actual_root: std::path::PathBuf, substitutions: &crate::Substitutions, + normalize_paths: bool, ) -> impl Iterator> + '_ { let walker = Walk::new(&expected_root); walker.map(move |r| { @@ -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));