Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dir)!: Rename path feature to dir to match mod #298

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/snapbox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion crates/snapbox/src/assert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl Assert {
}

/// # Directory Assertions
#[cfg(feature = "path")]
#[cfg(feature = "dir")]
impl Assert {
#[track_caller]
pub fn subset_eq(
Expand Down
10 changes: 5 additions & 5 deletions crates/snapbox/src/dir/diff.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(feature = "path")]
#[cfg(feature = "dir")]
use crate::filters::{Filter as _, FilterNewlines, FilterPaths, FilterRedactions};

#[derive(Clone, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -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<std::path::PathBuf>,
actual_root: impl Into<std::path::PathBuf>,
Expand All @@ -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,
Expand Down Expand Up @@ -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<std::path::PathBuf>,
actual_root: impl Into<std::path::PathBuf>,
Expand All @@ -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,
Expand Down
22 changes: 11 additions & 11 deletions crates/snapbox/src/dir/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -24,7 +24,7 @@ impl PathFixture {
Self(PathFixtureInner::Immutable(target.to_owned()))
}

#[cfg(feature = "path")]
#[cfg(feature = "dir")]
pub fn mutable_temp() -> Result<Self, crate::assert::Error> {
let temp = tempfile::tempdir().map_err(|e| e.to_string())?;
// We need to get the `/private` prefix on Mac so variable substitutions work
Expand All @@ -34,15 +34,15 @@ impl PathFixture {
Ok(Self(PathFixtureInner::MutableTemp { temp, path }))
}

#[cfg(feature = "path")]
#[cfg(feature = "dir")]
pub fn mutable_at(target: &std::path::Path) -> Result<Self, crate::assert::Error> {
let _ = std::fs::remove_dir_all(target);
std::fs::create_dir_all(target)
.map_err(|e| format!("Failed to create {}: {}", target.display(), e))?;
Ok(Self(PathFixtureInner::MutablePath(target.to_owned())))
}

#[cfg(feature = "path")]
#[cfg(feature = "dir")]
pub fn with_template(
self,
template_root: &std::path::Path,
Expand All @@ -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,
}
}
Expand All @@ -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()),
}
}
Expand All @@ -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(),
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/snapbox/src/dir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
16 changes: 8 additions & 8 deletions crates/snapbox/src/dir/ops.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -15,7 +15,7 @@ impl Walk {
}
}

#[cfg(feature = "path")]
#[cfg(feature = "dir")]
impl Iterator for Walk {
type Item = Result<std::path::PathBuf, std::io::Error>;

Expand All @@ -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<std::path::Path>,
dest: impl AsRef<std::path::Path>,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -157,11 +157,11 @@ pub fn resolve_dir(
}

pub(crate) fn canonicalize(path: &std::path::Path) -> Result<std::path::PathBuf, std::io::Error> {
#[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())
Expand Down
4 changes: 2 additions & 2 deletions crates/snapbox/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::path::PathBuf>,
Expand All @@ -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<std::path::PathBuf>,
Expand Down
2 changes: 1 addition & 1 deletion crates/trycmd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
Loading