From e764cdef9d4e440bf1fd01229a645677969d7309 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 23 Apr 2024 13:30:03 -0500 Subject: [PATCH] fix(dir): Rename path to dir --- crates/snapbox/src/assert/mod.rs | 6 ++--- crates/snapbox/src/data/source.rs | 2 +- crates/snapbox/src/{path => dir}/diff.rs | 4 +-- crates/snapbox/src/{path => dir}/fixture.rs | 2 +- crates/snapbox/src/{path => dir}/mod.rs | 0 crates/snapbox/src/{path => dir}/ops.rs | 0 crates/snapbox/src/{path => dir}/tests.rs | 0 crates/snapbox/src/lib.rs | 4 +-- crates/trycmd/src/runner.rs | 28 ++++++++++----------- crates/trycmd/src/schema.rs | 4 +-- 10 files changed, 25 insertions(+), 25 deletions(-) rename crates/snapbox/src/{path => dir}/diff.rs (99%) rename crates/snapbox/src/{path => dir}/fixture.rs (98%) rename crates/snapbox/src/{path => dir}/mod.rs (100%) rename crates/snapbox/src/{path => dir}/ops.rs (100%) rename crates/snapbox/src/{path => dir}/tests.rs (100%) diff --git a/crates/snapbox/src/assert/mod.rs b/crates/snapbox/src/assert/mod.rs index 8031595e..621f4de2 100644 --- a/crates/snapbox/src/assert/mod.rs +++ b/crates/snapbox/src/assert/mod.rs @@ -220,7 +220,7 @@ impl Assert { } let checks: Vec<_> = - crate::path::PathDiff::subset_eq_iter_inner(expected_root, actual_root).collect(); + crate::dir::PathDiff::subset_eq_iter_inner(expected_root, actual_root).collect(); self.verify(checks); } @@ -248,7 +248,7 @@ impl Assert { Action::Ignore | Action::Verify | Action::Overwrite => {} } - let checks: Vec<_> = crate::path::PathDiff::subset_matches_iter_inner( + let checks: Vec<_> = crate::dir::PathDiff::subset_matches_iter_inner( expected_root, actual_root, &self.substitutions, @@ -261,7 +261,7 @@ impl Assert { #[track_caller] fn verify( &self, - mut checks: Vec>, + mut checks: Vec>, ) { if checks.iter().all(Result::is_ok) { for check in checks { diff --git a/crates/snapbox/src/data/source.rs b/crates/snapbox/src/data/source.rs index 10e9b9d9..b72ec41f 100644 --- a/crates/snapbox/src/data/source.rs +++ b/crates/snapbox/src/data/source.rs @@ -63,7 +63,7 @@ impl From for DataSource { impl std::fmt::Display for DataSource { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match &self.inner { - DataSourceInner::Path(value) => crate::path::display_relpath(value).fmt(f), + DataSourceInner::Path(value) => crate::dir::display_relpath(value).fmt(f), DataSourceInner::Inline(value) => value.fmt(f), } } diff --git a/crates/snapbox/src/path/diff.rs b/crates/snapbox/src/dir/diff.rs similarity index 99% rename from crates/snapbox/src/path/diff.rs rename to crates/snapbox/src/dir/diff.rs index 1b02d37c..fd6c652f 100644 --- a/crates/snapbox/src/path/diff.rs +++ b/crates/snapbox/src/dir/diff.rs @@ -43,7 +43,7 @@ impl PathDiff { expected_root: std::path::PathBuf, actual_root: std::path::PathBuf, ) -> impl Iterator> { - let walker = crate::path::Walk::new(&expected_root); + let walker = crate::dir::Walk::new(&expected_root); walker.map(move |r| { let expected_path = r.map_err(|e| Self::Failure(e.to_string().into()))?; let rel = expected_path.strip_prefix(&expected_root).unwrap(); @@ -119,7 +119,7 @@ impl PathDiff { substitutions: &crate::Redactions, normalize_paths: bool, ) -> impl Iterator> + '_ { - let walker = crate::path::Walk::new(&expected_root); + let walker = crate::dir::Walk::new(&expected_root); walker.map(move |r| { let expected_path = r.map_err(|e| Self::Failure(e.to_string().into()))?; let rel = expected_path.strip_prefix(&expected_root).unwrap(); diff --git a/crates/snapbox/src/path/fixture.rs b/crates/snapbox/src/dir/fixture.rs similarity index 98% rename from crates/snapbox/src/path/fixture.rs rename to crates/snapbox/src/dir/fixture.rs index 640adeeb..a1ae0ced 100644 --- a/crates/snapbox/src/path/fixture.rs +++ b/crates/snapbox/src/dir/fixture.rs @@ -29,7 +29,7 @@ impl PathFixture { let temp = tempfile::tempdir().map_err(|e| e.to_string())?; // We need to get the `/private` prefix on Mac so variable substitutions work // correctly - let path = crate::path::canonicalize(temp.path()) + let path = crate::dir::canonicalize(temp.path()) .map_err(|e| format!("Failed to canonicalize {}: {}", temp.path().display(), e))?; Ok(Self(PathFixtureInner::MutableTemp { temp, path })) } diff --git a/crates/snapbox/src/path/mod.rs b/crates/snapbox/src/dir/mod.rs similarity index 100% rename from crates/snapbox/src/path/mod.rs rename to crates/snapbox/src/dir/mod.rs diff --git a/crates/snapbox/src/path/ops.rs b/crates/snapbox/src/dir/ops.rs similarity index 100% rename from crates/snapbox/src/path/ops.rs rename to crates/snapbox/src/dir/ops.rs diff --git a/crates/snapbox/src/path/tests.rs b/crates/snapbox/src/dir/tests.rs similarity index 100% rename from crates/snapbox/src/path/tests.rs rename to crates/snapbox/src/dir/tests.rs diff --git a/crates/snapbox/src/lib.rs b/crates/snapbox/src/lib.rs index e63ac638..bf56493d 100644 --- a/crates/snapbox/src/lib.rs +++ b/crates/snapbox/src/lib.rs @@ -34,7 +34,7 @@ //! [`Output`][std::process::Output]. //! //! Testing Filesystem Interactions: -//! - [`path::PathFixture`]: Working directory for tests +//! - [`dir::PathFixture`]: Working directory for tests //! - [`Assert`]: Diff a directory against files present in a pattern directory //! //! You can also build your own version of these with the lower-level building blocks these are @@ -66,8 +66,8 @@ mod macros; pub mod assert; pub mod cmd; pub mod data; +pub mod dir; pub mod filters; -pub mod path; pub mod report; pub mod utils; diff --git a/crates/trycmd/src/runner.rs b/crates/trycmd/src/runner.rs index 5449bbbb..86de15e8 100644 --- a/crates/trycmd/src/runner.rs +++ b/crates/trycmd/src/runner.rs @@ -13,8 +13,8 @@ use std::io::stderr; use rayon::prelude::*; use snapbox::data::DataFormat; +use snapbox::dir::FileType; use snapbox::filters::{Filter as _, FilterNewlines, FilterPaths, FilterRedactions}; -use snapbox::path::FileType; use snapbox::IntoData; #[derive(Debug)] @@ -188,7 +188,7 @@ impl Case { .map(|p| { sequence.fs.rel_cwd().map(|rel| { let p = p.join(rel); - snapbox::path::strip_trailing_slash(&p).to_owned() + snapbox::dir::strip_trailing_slash(&p).to_owned() }) }) .transpose() @@ -504,7 +504,7 @@ impl Case { } else { let fixture_root = self.path.with_extension("out"); if fixture_root.exists() { - for status in snapbox::path::PathDiff::subset_matches_iter( + for status in snapbox::dir::PathDiff::subset_matches_iter( fixture_root, actual_root, substitutions, @@ -878,11 +878,11 @@ impl FileStatus { } } -impl From for FileStatus { - fn from(other: snapbox::path::PathDiff) -> Self { +impl From for FileStatus { + fn from(other: snapbox::dir::PathDiff) -> Self { match other { - snapbox::path::PathDiff::Failure(err) => FileStatus::Failure(err), - snapbox::path::PathDiff::TypeMismatch { + snapbox::dir::PathDiff::Failure(err) => FileStatus::Failure(err), + snapbox::dir::PathDiff::TypeMismatch { expected_path, actual_path, expected_type, @@ -893,7 +893,7 @@ impl From for FileStatus { actual_type, expected_type, }, - snapbox::path::PathDiff::LinkMismatch { + snapbox::dir::PathDiff::LinkMismatch { expected_path, actual_path, expected_target, @@ -904,7 +904,7 @@ impl From for FileStatus { actual_target, expected_target, }, - snapbox::path::PathDiff::ContentMismatch { + snapbox::dir::PathDiff::ContentMismatch { expected_path, actual_path, expected_content, @@ -1016,20 +1016,20 @@ fn fs_context( cwd: Option<&std::path::Path>, sandbox: bool, mode: &crate::Mode, -) -> Result { +) -> Result { if sandbox { #[cfg(feature = "filesystem")] match mode { crate::Mode::Dump(root) => { let target = root.join(path.with_extension("out").file_name().unwrap()); - let mut context = snapbox::path::PathFixture::mutable_at(&target)?; + let mut context = snapbox::dir::PathFixture::mutable_at(&target)?; if let Some(cwd) = cwd { context = context.with_template(cwd)?; } Ok(context) } crate::Mode::Fail | crate::Mode::Overwrite => { - let mut context = snapbox::path::PathFixture::mutable_temp()?; + let mut context = snapbox::dir::PathFixture::mutable_temp()?; if let Some(cwd) = cwd { context = context.with_template(cwd)?; } @@ -1040,7 +1040,7 @@ fn fs_context( Err("Sandboxing is disabled".into()) } else { Ok(cwd - .map(snapbox::path::PathFixture::immutable) - .unwrap_or_else(snapbox::path::PathFixture::none)) + .map(snapbox::dir::PathFixture::immutable) + .unwrap_or_else(snapbox::dir::PathFixture::none)) } } diff --git a/crates/trycmd/src/schema.rs b/crates/trycmd/src/schema.rs index eb78705a..1a9512f2 100644 --- a/crates/trycmd/src/schema.rs +++ b/crates/trycmd/src/schema.rs @@ -109,13 +109,13 @@ impl TryCmd { .fs .base .take() - .map(|p| snapbox::path::resolve_dir(p).map_err(|e| e.to_string())) + .map(|p| snapbox::dir::resolve_dir(p).map_err(|e| e.to_string())) .transpose()?; sequence.fs.cwd = sequence .fs .cwd .take() - .map(|p| snapbox::path::resolve_dir(p).map_err(|e| e.to_string())) + .map(|p| snapbox::dir::resolve_dir(p).map_err(|e| e.to_string())) .transpose()?; Ok(sequence)