From 5fc67deec33fc586ee68896b4a63d22c458114f7 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 23 Apr 2024 20:55:26 -0500 Subject: [PATCH] fix(dir)!: Rename `path` feature to `dir` to match mod --- crates/snapbox/Cargo.toml | 4 ++-- crates/snapbox/src/assert/mod.rs | 2 +- crates/snapbox/src/dir/diff.rs | 10 +++++----- crates/snapbox/src/dir/fixture.rs | 22 +++++++++++----------- crates/snapbox/src/dir/mod.rs | 6 +++--- crates/snapbox/src/dir/ops.rs | 16 ++++++++-------- crates/snapbox/src/lib.rs | 4 ++-- crates/trycmd/Cargo.toml | 2 +- 8 files changed, 33 insertions(+), 33 deletions(-) diff --git a/crates/snapbox/Cargo.toml b/crates/snapbox/Cargo.toml index 8d62bdf3..341392c6 100644 --- a/crates/snapbox/Cargo.toml +++ b/crates/snapbox/Cargo.toml @@ -34,8 +34,8 @@ default = ["color-auto", "diff"] ## Smarter binary file detection detect-encoding = ["dep:content_inspector"] -## Snapshotting of paths -path = ["dep:tempfile", "dep:walkdir", "dep:dunce", "detect-encoding", "dep:filetime"] +## Snapshotting of directories +dir = ["dep:tempfile", "dep:walkdir", "dep:dunce", "detect-encoding", "dep:filetime"] ## Snapshotting of commands cmd = ["dep:os_pipe", "dep:wait-timeout", "dep:libc", "dep:windows-sys"] ## Building of examples for snapshotting diff --git a/crates/snapbox/src/assert/mod.rs b/crates/snapbox/src/assert/mod.rs index 621f4de2..df4320ef 100644 --- a/crates/snapbox/src/assert/mod.rs +++ b/crates/snapbox/src/assert/mod.rs @@ -197,7 +197,7 @@ impl Assert { } /// # Directory Assertions -#[cfg(feature = "path")] +#[cfg(feature = "dir")] impl Assert { #[track_caller] pub fn subset_eq( diff --git a/crates/snapbox/src/dir/diff.rs b/crates/snapbox/src/dir/diff.rs index fd6c652f..59d0f025 100644 --- a/crates/snapbox/src/dir/diff.rs +++ b/crates/snapbox/src/dir/diff.rs @@ -1,4 +1,4 @@ -#[cfg(feature = "path")] +#[cfg(feature = "dir")] use crate::filters::{Filter as _, FilterNewlines, FilterPaths, FilterRedactions}; #[derive(Clone, Debug, PartialEq, Eq)] @@ -28,7 +28,7 @@ impl PathDiff { /// Report differences between `actual_root` and `pattern_root` /// /// Note: Requires feature flag `path` - #[cfg(feature = "path")] + #[cfg(feature = "dir")] pub fn subset_eq_iter( pattern_root: impl Into, actual_root: impl Into, @@ -38,7 +38,7 @@ impl PathDiff { Self::subset_eq_iter_inner(pattern_root, actual_root) } - #[cfg(feature = "path")] + #[cfg(feature = "dir")] pub(crate) fn subset_eq_iter_inner( expected_root: std::path::PathBuf, actual_root: std::path::PathBuf, @@ -101,7 +101,7 @@ impl PathDiff { /// Report differences between `actual_root` and `pattern_root` /// /// Note: Requires feature flag `path` - #[cfg(feature = "path")] + #[cfg(feature = "dir")] pub fn subset_matches_iter( pattern_root: impl Into, actual_root: impl Into, @@ -112,7 +112,7 @@ impl PathDiff { Self::subset_matches_iter_inner(pattern_root, actual_root, substitutions, true) } - #[cfg(feature = "path")] + #[cfg(feature = "dir")] pub(crate) fn subset_matches_iter_inner( expected_root: std::path::PathBuf, actual_root: std::path::PathBuf, diff --git a/crates/snapbox/src/dir/fixture.rs b/crates/snapbox/src/dir/fixture.rs index a1ae0ced..b17e608f 100644 --- a/crates/snapbox/src/dir/fixture.rs +++ b/crates/snapbox/src/dir/fixture.rs @@ -6,9 +6,9 @@ pub struct PathFixture(PathFixtureInner); enum PathFixtureInner { None, Immutable(std::path::PathBuf), - #[cfg(feature = "path")] + #[cfg(feature = "dir")] MutablePath(std::path::PathBuf), - #[cfg(feature = "path")] + #[cfg(feature = "dir")] MutableTemp { temp: tempfile::TempDir, path: std::path::PathBuf, @@ -24,7 +24,7 @@ impl PathFixture { Self(PathFixtureInner::Immutable(target.to_owned())) } - #[cfg(feature = "path")] + #[cfg(feature = "dir")] pub fn mutable_temp() -> Result { let temp = tempfile::tempdir().map_err(|e| e.to_string())?; // We need to get the `/private` prefix on Mac so variable substitutions work @@ -34,7 +34,7 @@ impl PathFixture { Ok(Self(PathFixtureInner::MutableTemp { temp, path })) } - #[cfg(feature = "path")] + #[cfg(feature = "dir")] pub fn mutable_at(target: &std::path::Path) -> Result { let _ = std::fs::remove_dir_all(target); std::fs::create_dir_all(target) @@ -42,7 +42,7 @@ impl PathFixture { Ok(Self(PathFixtureInner::MutablePath(target.to_owned()))) } - #[cfg(feature = "path")] + #[cfg(feature = "dir")] pub fn with_template( self, template_root: &std::path::Path, @@ -67,9 +67,9 @@ impl PathFixture { pub fn is_mutable(&self) -> bool { match &self.0 { PathFixtureInner::None | PathFixtureInner::Immutable(_) => false, - #[cfg(feature = "path")] + #[cfg(feature = "dir")] PathFixtureInner::MutablePath(_) => true, - #[cfg(feature = "path")] + #[cfg(feature = "dir")] PathFixtureInner::MutableTemp { .. } => true, } } @@ -78,9 +78,9 @@ impl PathFixture { match &self.0 { PathFixtureInner::None => None, PathFixtureInner::Immutable(path) => Some(path.as_path()), - #[cfg(feature = "path")] + #[cfg(feature = "dir")] PathFixtureInner::MutablePath(path) => Some(path.as_path()), - #[cfg(feature = "path")] + #[cfg(feature = "dir")] PathFixtureInner::MutableTemp { path, .. } => Some(path.as_path()), } } @@ -89,9 +89,9 @@ impl PathFixture { pub fn close(self) -> Result<(), std::io::Error> { match self.0 { PathFixtureInner::None | PathFixtureInner::Immutable(_) => Ok(()), - #[cfg(feature = "path")] + #[cfg(feature = "dir")] PathFixtureInner::MutablePath(_) => Ok(()), - #[cfg(feature = "path")] + #[cfg(feature = "dir")] PathFixtureInner::MutableTemp { temp, .. } => temp.close(), } } diff --git a/crates/snapbox/src/dir/mod.rs b/crates/snapbox/src/dir/mod.rs index bfd01979..0e083da0 100644 --- a/crates/snapbox/src/dir/mod.rs +++ b/crates/snapbox/src/dir/mod.rs @@ -9,14 +9,14 @@ mod tests; pub use diff::FileType; pub use diff::PathDiff; pub use fixture::PathFixture; -#[cfg(feature = "path")] +#[cfg(feature = "dir")] pub use ops::copy_template; pub use ops::resolve_dir; pub use ops::strip_trailing_slash; -#[cfg(feature = "path")] +#[cfg(feature = "dir")] pub use ops::Walk; -#[cfg(feature = "path")] +#[cfg(feature = "dir")] pub(crate) use ops::canonicalize; pub(crate) use ops::display_relpath; pub(crate) use ops::shallow_copy; diff --git a/crates/snapbox/src/dir/ops.rs b/crates/snapbox/src/dir/ops.rs index a209f279..9f5ec7e2 100644 --- a/crates/snapbox/src/dir/ops.rs +++ b/crates/snapbox/src/dir/ops.rs @@ -1,12 +1,12 @@ /// Recursively walk a path /// /// Note: Ignores `.keep` files -#[cfg(feature = "path")] +#[cfg(feature = "dir")] pub struct Walk { inner: walkdir::IntoIter, } -#[cfg(feature = "path")] +#[cfg(feature = "dir")] impl Walk { pub fn new(path: &std::path::Path) -> Self { Self { @@ -15,7 +15,7 @@ impl Walk { } } -#[cfg(feature = "path")] +#[cfg(feature = "dir")] impl Iterator for Walk { type Item = Result; @@ -39,7 +39,7 @@ impl Iterator for Walk { /// Note: Generally you'll use [`PathFixture::with_template`][super::PathFixture::with_template] instead. /// /// Note: Ignores `.keep` files -#[cfg(feature = "path")] +#[cfg(feature = "dir")] pub fn copy_template( source: impl AsRef, dest: impl AsRef, @@ -110,7 +110,7 @@ pub(crate) fn shallow_copy( Ok(()) } -#[cfg(feature = "path")] +#[cfg(feature = "dir")] fn copy_stats( source_meta: &std::fs::Metadata, dest: &std::path::Path, @@ -121,7 +121,7 @@ fn copy_stats( Ok(()) } -#[cfg(not(feature = "path"))] +#[cfg(not(feature = "dir"))] fn copy_stats( _source_meta: &std::fs::Metadata, _dest: &std::path::Path, @@ -157,11 +157,11 @@ pub fn resolve_dir( } pub(crate) fn canonicalize(path: &std::path::Path) -> Result { - #[cfg(feature = "path")] + #[cfg(feature = "dir")] { dunce::canonicalize(path) } - #[cfg(not(feature = "path"))] + #[cfg(not(feature = "dir"))] { // Hope for the best Ok(strip_trailing_slash(path).to_owned()) diff --git a/crates/snapbox/src/lib.rs b/crates/snapbox/src/lib.rs index bf56493d..4fd003f4 100644 --- a/crates/snapbox/src/lib.rs +++ b/crates/snapbox/src/lib.rs @@ -98,7 +98,7 @@ pub mod prelude { /// let expected_root = "tests/snapshots/output.txt"; /// snapbox::assert_subset_eq(expected_root, output_root); /// ``` -#[cfg(feature = "path")] +#[cfg(feature = "dir")] #[track_caller] pub fn assert_subset_eq( expected_root: impl Into, @@ -125,7 +125,7 @@ pub fn assert_subset_eq( /// let expected_root = "tests/snapshots/output.txt"; /// snapbox::assert_subset_matches(expected_root, output_root); /// ``` -#[cfg(feature = "path")] +#[cfg(feature = "dir")] #[track_caller] pub fn assert_subset_matches( pattern_root: impl Into, diff --git a/crates/trycmd/Cargo.toml b/crates/trycmd/Cargo.toml index e9fca2ed..64155717 100644 --- a/crates/trycmd/Cargo.toml +++ b/crates/trycmd/Cargo.toml @@ -33,7 +33,7 @@ default = ["color-auto", "filesystem", "diff"] color = ["snapbox/color", "dep:anstream"] color-auto = ["snapbox/color-auto"] diff = ["snapbox/diff"] -filesystem = ["snapbox/path"] +filesystem = ["snapbox/dir"] schema = ["dep:schemars", "dep:serde_json"] examples = ["snapbox/examples"]