diff --git a/Cargo.lock b/Cargo.lock index 49f2127c..b4554403 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -805,9 +805,7 @@ dependencies = [ "dunce", "escargot", "filetime", - "ignore", "libc", - "libtest-mimic", "normalize-line-endings", "os_pipe", "serde", diff --git a/crates/snapbox/Cargo.toml b/crates/snapbox/Cargo.toml index 6a410412..0e4e8752 100644 --- a/crates/snapbox/Cargo.toml +++ b/crates/snapbox/Cargo.toml @@ -32,8 +32,6 @@ default = ["color-auto", "diff"] #! Feature Flags -## Simple input/output test harness -harness = ["dep:libtest-mimic", "dep:ignore"] ## Smarter binary file detection detect-encoding = ["dep:content_inspector"] ## Snapshotting of directories @@ -71,9 +69,6 @@ name = "snap-fixture" # For `snapbox`s tests only normalize-line-endings = "0.3.0" snapbox-macros = { path = "../snapbox-macros", version = "0.3.9" } -libtest-mimic = { version = "0.7.0", optional = true } -ignore = { version = "0.4", optional = true } - content_inspector = { version = "0.2.4", optional = true } tempfile = { version = "3.0", optional = true } diff --git a/crates/snapbox/src/assert/mod.rs b/crates/snapbox/src/assert/mod.rs index 467ba554..de6326cd 100644 --- a/crates/snapbox/src/assert/mod.rs +++ b/crates/snapbox/src/assert/mod.rs @@ -79,75 +79,6 @@ impl Assert { } } - /// Check if a value is the same as an expected value - /// - /// When the content is text, newlines are normalized. - /// - /// ```rust - /// # use snapbox::Assert; - /// let actual = "something"; - /// let expected = "something"; - /// Assert::new().eq(expected, actual); - /// ``` - /// - /// Can combine this with [`file!`][crate::file] - /// ```rust,no_run - /// # use snapbox::Assert; - /// # use snapbox::file; - /// let actual = "something"; - /// Assert::new().eq(file!["output.txt"], actual); - /// ``` - #[track_caller] - #[deprecated( - since = "0.5.11", - note = "Replaced with `Assert::eq_(actual, expected.raw())`" - )] - pub fn eq(&self, expected: impl Into, actual: impl Into) { - let expected = expected.into(); - let actual = actual.into(); - if let Err(err) = self.try_eq(Some(&"In-memory"), actual, expected.raw()) { - err.panic(); - } - } - - /// Check if a value matches a pattern - /// - /// Pattern syntax: - /// - `...` is a line-wildcard when on a line by itself - /// - `[..]` is a character-wildcard when inside a line - /// - `[EXE]` matches `.exe` on Windows - /// - /// Normalization: - /// - Newlines - /// - `\` to `/` - /// - /// ```rust - /// # use snapbox::Assert; - /// let actual = "something"; - /// let expected = "so[..]g"; - /// Assert::new().matches(expected, actual); - /// ``` - /// - /// Can combine this with [`file!`][crate::file] - /// ```rust,no_run - /// # use snapbox::Assert; - /// # use snapbox::file; - /// let actual = "something"; - /// Assert::new().matches(file!["output.txt"], actual); - /// ``` - #[track_caller] - #[deprecated( - since = "0.5.11", - note = "Replaced with `Assert::eq_(actual, expected)`" - )] - pub fn matches(&self, pattern: impl Into, actual: impl Into) { - let pattern = pattern.into(); - let actual = actual.into(); - if let Err(err) = self.try_eq(Some(&"In-memory"), actual, pattern) { - err.panic(); - } - } - pub fn try_eq( &self, actual_name: Option<&dyn std::fmt::Display>, diff --git a/crates/snapbox/src/cmd.rs b/crates/snapbox/src/cmd.rs index f13471a2..95e313cb 100644 --- a/crates/snapbox/src/cmd.rs +++ b/crates/snapbox/src/cmd.rs @@ -630,76 +630,6 @@ impl OutputAssert { self.stdout_eq_inner(expected) } - /// Ensure the command wrote the expected data to `stdout`. - /// - /// ```rust,no_run - /// use snapbox::cmd::Command; - /// use snapbox::cmd::cargo_bin; - /// - /// let assert = Command::new(cargo_bin("snap-fixture")) - /// .env("stdout", "hello") - /// .env("stderr", "world") - /// .assert() - /// .stdout_eq("hello"); - /// ``` - /// - /// Can combine this with [`file!`][crate::file] - /// ```rust,no_run - /// use snapbox::cmd::Command; - /// use snapbox::cmd::cargo_bin; - /// use snapbox::file; - /// - /// let assert = Command::new(cargo_bin("snap-fixture")) - /// .env("stdout", "hello") - /// .env("stderr", "world") - /// .assert() - /// .stdout_eq(file!["stdout.log"]); - /// ``` - #[track_caller] - #[deprecated( - since = "0.5.11", - note = "Replaced with `OutputAssert::stdout_eq_(expected.raw())`" - )] - pub fn stdout_eq(self, expected: impl Into) -> Self { - let expected = expected.into(); - self.stdout_eq_inner(expected.raw()) - } - - /// Ensure the command wrote the expected data to `stdout`. - /// - /// ```rust,no_run - /// use snapbox::cmd::Command; - /// use snapbox::cmd::cargo_bin; - /// - /// let assert = Command::new(cargo_bin("snap-fixture")) - /// .env("stdout", "hello") - /// .env("stderr", "world") - /// .assert() - /// .stdout_matches("he[..]o"); - /// ``` - /// - /// Can combine this with [`file!`][crate::file] - /// ```rust,no_run - /// use snapbox::cmd::Command; - /// use snapbox::cmd::cargo_bin; - /// use snapbox::file; - /// - /// let assert = Command::new(cargo_bin("snap-fixture")) - /// .env("stdout", "hello") - /// .env("stderr", "world") - /// .assert() - /// .stdout_matches(file!["stdout.log"]); - /// ``` - #[track_caller] - #[deprecated( - since = "0.5.11", - note = "Replaced with `OutputAssert::stdout_eq_(expected)`" - )] - pub fn stdout_matches(self, expected: impl Into) -> Self { - let expected = expected.into(); - self.stdout_eq_inner(expected) - } - #[track_caller] fn stdout_eq_inner(self, expected: crate::Data) -> Self { let actual = self.output.stdout.as_slice().into_data(); @@ -752,76 +682,6 @@ impl OutputAssert { self.stderr_eq_inner(expected) } - /// Ensure the command wrote the expected data to `stderr`. - /// - /// ```rust,no_run - /// use snapbox::cmd::Command; - /// use snapbox::cmd::cargo_bin; - /// - /// let assert = Command::new(cargo_bin("snap-fixture")) - /// .env("stdout", "hello") - /// .env("stderr", "world") - /// .assert() - /// .stderr_eq("world"); - /// ``` - /// - /// Can combine this with [`file!`][crate::file] - /// ```rust,no_run - /// use snapbox::cmd::Command; - /// use snapbox::cmd::cargo_bin; - /// use snapbox::file; - /// - /// let assert = Command::new(cargo_bin("snap-fixture")) - /// .env("stdout", "hello") - /// .env("stderr", "world") - /// .assert() - /// .stderr_eq(file!["stderr.log"]); - /// ``` - #[track_caller] - #[deprecated( - since = "0.5.11", - note = "Replaced with `OutputAssert::stderr_eq_(expected.raw())`" - )] - pub fn stderr_eq(self, expected: impl Into) -> Self { - let expected = expected.into(); - self.stderr_eq_inner(expected.raw()) - } - - /// Ensure the command wrote the expected data to `stderr`. - /// - /// ```rust,no_run - /// use snapbox::cmd::Command; - /// use snapbox::cmd::cargo_bin; - /// - /// let assert = Command::new(cargo_bin("snap-fixture")) - /// .env("stdout", "hello") - /// .env("stderr", "world") - /// .assert() - /// .stderr_matches("wo[..]d"); - /// ``` - /// - /// Can combine this with [`file!`][crate::file] - /// ```rust,no_run - /// use snapbox::cmd::Command; - /// use snapbox::cmd::cargo_bin; - /// use snapbox::file; - /// - /// let assert = Command::new(cargo_bin("snap-fixture")) - /// .env("stdout", "hello") - /// .env("stderr", "world") - /// .assert() - /// .stderr_matches(file!["stderr.log"]); - /// ``` - #[track_caller] - #[deprecated( - since = "0.5.11", - note = "Replaced with `OutputAssert::stderr_eq_(expected)`" - )] - pub fn stderr_matches(self, expected: impl Into) -> Self { - let expected = expected.into(); - self.stderr_eq_inner(expected) - } - #[track_caller] fn stderr_eq_inner(self, expected: crate::Data) -> Self { let actual = self.output.stderr.as_slice().into_data(); diff --git a/crates/snapbox/src/data/mod.rs b/crates/snapbox/src/data/mod.rs index e345e04b..268fc733 100644 --- a/crates/snapbox/src/data/mod.rs +++ b/crates/snapbox/src/data/mod.rs @@ -2,20 +2,12 @@ mod filters; mod format; -mod normalize; mod runtime; mod source; #[cfg(test)] mod tests; pub use format::DataFormat; -pub use normalize::Normalize; -#[allow(deprecated)] -pub use normalize::NormalizeMatches; -#[allow(deprecated)] -pub use normalize::NormalizeNewlines; -#[allow(deprecated)] -pub use normalize::NormalizePaths; pub use source::DataSource; pub use source::Inline; #[doc(hidden)] @@ -336,14 +328,6 @@ impl Data { .map_err(|e| format!("Failed to write {}: {}", path.display(), e).into()) } - /// Post-process text - /// - /// See [utils][crate::utils] - #[deprecated(since = "0.5.11", note = "Replaced with `Normalize::normalize`")] - pub fn normalize(self, op: impl Normalize) -> Self { - op.filter(self) - } - /// Return the underlying `String` /// /// Note: this will not inspect binary data for being a valid `String`. diff --git a/crates/snapbox/src/data/normalize.rs b/crates/snapbox/src/data/normalize.rs deleted file mode 100644 index da79f8e0..00000000 --- a/crates/snapbox/src/data/normalize.rs +++ /dev/null @@ -1,24 +0,0 @@ -#![allow(deprecated)] - -use super::Data; - -pub use crate::filter::Filter as Normalize; - -#[deprecated(since = "0.5.11", note = "Replaced with `filter::FilterNewlines")] -pub struct NormalizeNewlines; -impl Normalize for NormalizeNewlines { - fn normalize(&self, data: Data) -> Data { - crate::filter::NormalizeNewlines.normalize(data) - } -} - -#[deprecated(since = "0.5.11", note = "Replaced with `filter::FilterPaths")] -pub struct NormalizePaths; -impl Normalize for NormalizePaths { - fn normalize(&self, data: Data) -> Data { - crate::filter::NormalizePaths.normalize(data) - } -} - -#[deprecated(since = "0.5.11", note = "Replaced with `filter::FilterRedactions")] -pub type NormalizeMatches<'a> = crate::filter::FilterRedactions<'a>; diff --git a/crates/snapbox/src/data/source.rs b/crates/snapbox/src/data/source.rs index 6e0aae71..3a32f399 100644 --- a/crates/snapbox/src/data/source.rs +++ b/crates/snapbox/src/data/source.rs @@ -87,33 +87,6 @@ impl Inline { self } - /// Initialize `Self` as [`format`][crate::data::DataFormat] or [`Error`][crate::data::DataFormat::Error] - /// - /// This is generally used for `expected` data - /// - /// ```rust - /// # #[cfg(feature = "json")] { - /// use snapbox::str; - /// - /// let expected = str![[r#"{"hello": "world"}"#]] - /// .is(snapbox::data::DataFormat::Json); - /// assert_eq!(expected.format(), snapbox::data::DataFormat::Json); - /// # } - /// ``` - // #[deprecated(since = "0.5.11", note = "Replaced with `IntoData::is`")] // can't deprecate - // because trait will always be preferred - pub fn is(self, format: super::DataFormat) -> super::Data { - let data: super::Data = self.into(); - data.is(format) - } - - /// Deprecated, replaced with [`Inline::is`] - #[deprecated(since = "0.5.2", note = "Replaced with `Inline::is`")] - pub fn coerce_to(self, format: super::DataFormat) -> super::Data { - let data: super::Data = self.into(); - data.coerce_to(format) - } - pub(crate) fn trimmed(&self) -> String { let mut data = self.data; if data.contains('\n') { diff --git a/crates/snapbox/src/filter/mod.rs b/crates/snapbox/src/filter/mod.rs index 27fd531b..7aa1da9e 100644 --- a/crates/snapbox/src/filter/mod.rs +++ b/crates/snapbox/src/filter/mod.rs @@ -15,35 +15,12 @@ pub use redactions::RedactedValue; pub use redactions::Redactions; pub trait Filter { - #[deprecated(since = "0.5.11", note = "Replaced with `Filter::filter`")] - fn normalize(&self, data: Data) -> Data; - fn filter(&self, data: Data) -> Data { - #[allow(deprecated)] - self.normalize(data) - } -} - -#[deprecated(since = "0.5.11", note = "Replaced with `filter::FilterNewlines")] -pub struct NormalizeNewlines; -#[allow(deprecated)] -impl Filter for NormalizeNewlines { - fn normalize(&self, data: Data) -> Data { - FilterNewlines.normalize(data) - } -} - -#[deprecated(since = "0.5.11", note = "Replaced with `filter::FilterPaths")] -pub struct NormalizePaths; -#[allow(deprecated)] -impl Filter for NormalizePaths { - fn normalize(&self, data: Data) -> Data { - FilterPaths.normalize(data) - } + fn filter(&self, data: Data) -> Data; } pub struct FilterNewlines; impl Filter for FilterNewlines { - fn normalize(&self, data: Data) -> Data { + fn filter(&self, data: Data) -> Data { let source = data.source; let filters = data.filters; let inner = match data.inner { @@ -84,7 +61,7 @@ fn normalize_lines_chars(data: impl Iterator) -> impl Iterator Data { + fn filter(&self, data: Data) -> Data { let source = data.source; let filters = data.filters; let inner = match data.inner { @@ -143,7 +120,7 @@ impl<'a> FilterRedactions<'a> { } impl Filter for FilterRedactions<'_> { - fn normalize(&self, data: Data) -> Data { + fn filter(&self, data: Data) -> Data { let source = data.source; let filters = data.filters; let inner = match data.inner { diff --git a/crates/snapbox/src/filter/redactions.rs b/crates/snapbox/src/filter/redactions.rs index b488b6c5..92ff511f 100644 --- a/crates/snapbox/src/filter/redactions.rs +++ b/crates/snapbox/src/filter/redactions.rs @@ -132,10 +132,9 @@ where if inner.is_empty() { Self { inner: None } } else { - #[allow(deprecated)] Self { - inner: Some(RedactedValueInner::String(crate::utils::normalize_text( - &inner, + inner: Some(RedactedValueInner::String(crate::filter::normalize_paths( + &crate::filter::normalize_lines(&inner), ))), } } diff --git a/crates/snapbox/src/harness.rs b/crates/snapbox/src/harness.rs deleted file mode 100644 index 0a61d76d..00000000 --- a/crates/snapbox/src/harness.rs +++ /dev/null @@ -1,166 +0,0 @@ -//! [`Harness`] for discovering test inputs and asserting against snapshot files -//! -//! This is a custom test harness and should be put in its own test binary with -//! [`test.harness = false`](https://doc.rust-lang.org/stable/cargo/reference/cargo-targets.html#the-harness-field). -//! -//! # Examples -//! -//! ```rust,no_run -//! snapbox::harness::Harness::new( -//! "tests/fixtures/invalid", -//! setup, -//! test, -//! ) -//! .select(["tests/cases/*.in"]) -//! .test(); -//! -//! fn setup(input_path: std::path::PathBuf) -> snapbox::harness::Case { -//! let name = input_path.file_name().unwrap().to_str().unwrap().to_owned(); -//! let expected = input_path.with_extension("out"); -//! snapbox::harness::Case { -//! name, -//! fixture: input_path, -//! expected, -//! } -//! } -//! -//! fn test(input_path: &std::path::Path) -> Result> { -//! let raw = std::fs::read_to_string(input_path)?; -//! let num = raw.parse::()?; -//! -//! let actual = num + 10; -//! -//! Ok(actual) -//! } -//! ``` - -#![allow(deprecated)] - -use crate::data::DataFormat; -use crate::Action; - -use libtest_mimic::Trial; - -/// [`Fallback dependenciesforfallback-dependenciess -/// [`Build script directivesck-build-script-directivess -/// [`When to use packages or workspaces?ck-when-to-use-packages-or-workspacess -/// [`Cargo and rustupes?cargo-and-rustups -/// -/// See [`harness`][crate::harness] for more details -#[deprecated(since = "0.5.12", note = "Replaced with `tryfn` crate")] -pub struct Harness { - root: std::path::PathBuf, - overrides: Option, - setup: S, - test: T, - config: crate::Assert, -} - -impl Harness -where - I: std::fmt::Display, - E: std::fmt::Display, - S: Fn(std::path::PathBuf) -> Case + Send + Sync + 'static, - T: Fn(&std::path::Path) -> Result + Send + Sync + 'static + Clone, -{ - /// Specify where the test scenarios - /// - /// - `input_root`: where to find the files. See [`Self::select`] for restricting what files - /// are considered - /// - `setup`: Given a path, choose the test name and the output location - /// - `test`: Given a path, return the actual output value - pub fn new(input_root: impl Into, setup: S, test: T) -> Self { - Self { - root: input_root.into(), - overrides: None, - setup, - test, - config: crate::Assert::new().action_env(crate::assert::DEFAULT_ACTION_ENV), - } - } - - /// Path patterns for selecting input files - /// - /// This used gitignore syntax - pub fn select<'p>(mut self, patterns: impl IntoIterator) -> Self { - let mut overrides = ignore::overrides::OverrideBuilder::new(&self.root); - for line in patterns { - overrides.add(line).unwrap(); - } - self.overrides = Some(overrides.build().unwrap()); - self - } - - /// Read the failure action from an environment variable - #[deprecated(since = "0.1.0", note = "Replaced with `Harness::with_assert`")] - pub fn action_env(mut self, var_name: &str) -> Self { - self.config = self.config.action_env(var_name); - self - } - - /// Override the failure action - #[deprecated(since = "0.1.0", note = "Replaced with `Harness::with_assert`")] - pub fn action(mut self, action: Action) -> Self { - self.config = self.config.action(action); - self - } - - /// Customize the assertion behavior - pub fn with_assert(mut self, config: crate::Assert) -> Self { - self.config = config; - self - } - - /// Run tests - pub fn test(self) -> ! { - let mut walk = ignore::WalkBuilder::new(&self.root); - walk.standard_filters(false); - let tests = walk.build().filter_map(|entry| { - let entry = entry.unwrap(); - let is_dir = entry.file_type().map(|f| f.is_dir()).unwrap_or(false); - let path = entry.into_path(); - if let Some(overrides) = &self.overrides { - overrides - .matched(&path, is_dir) - .is_whitelist() - .then_some(path) - } else { - Some(path) - } - }); - - let shared_config = std::sync::Arc::new(self.config); - let tests: Vec<_> = tests - .into_iter() - .map(|path| { - let case = (self.setup)(path); - let test = self.test.clone(); - let config = shared_config.clone(); - Trial::test(case.name.clone(), move || { - let expected = crate::Data::read_from(&case.expected, Some(DataFormat::Text)); - let actual = (test)(&case.fixture)?; - let actual = actual.to_string(); - let actual = crate::Data::text(actual); - config.try_eq(Some(&case.name), actual, expected.raw())?; - Ok(()) - }) - .with_ignored_flag(shared_config.action == Action::Ignore) - }) - .collect(); - - let args = libtest_mimic::Arguments::from_args(); - libtest_mimic::run(&args, tests).exit() - } -} - -/// A test case enumerated by the [`Harness`] with data from the `setup` function -/// -/// See [`harness`][crate::harness] for more details -pub struct Case { - /// Display name - pub name: String, - /// Input for the test - pub fixture: std::path::PathBuf, - /// What the actual output should be compared against or updated - pub expected: std::path::PathBuf, -} diff --git a/crates/snapbox/src/lib.rs b/crates/snapbox/src/lib.rs index 4916f569..eda1e28b 100644 --- a/crates/snapbox/src/lib.rs +++ b/crates/snapbox/src/lib.rs @@ -16,6 +16,7 @@ //! - [trycmd](https://crates.io/crates/trycmd): For running a lot of blunt tests (limited test predicates) //! - Particular attention is given to allow the test data to be pulled into documentation, like //! with [mdbook](https://rust-lang.github.io/mdBook/) +//! - [tryfn](https://crates.io/crates/tryfn): For running a lot of simple input/output tests //! - `snapbox`: When you want something like `trycmd` in one off //! cases or you need to customize `trycmd`s behavior. //! - [assert_cmd](https://crates.io/crates/assert_cmd) + @@ -27,7 +28,6 @@ //! //! Testing Functions: //! - [`assert_data_eq!`] for quick and dirty snapshotting -//! - [`harness::Harness`] for discovering test inputs and asserting against snapshot files: //! //! Testing Commands: //! - [`cmd::Command`]: Process spawning for testing of non-interactive commands @@ -35,7 +35,7 @@ //! [`Output`][std::process::Output]. //! //! Testing Filesystem Interactions: -//! - [`path::PathFixture`]: Working directory for tests +//! - [`dir::DirRoot`]: 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 @@ -58,38 +58,6 @@ //! .eq_(actual, snapbox::file!["help_output_is_clean.txt"]); //! ``` //! -//! [`harness::Harness`] -#![cfg_attr(not(feature = "harness"), doc = " ```rust,ignore")] -#![cfg_attr(feature = "harness", doc = " ```rust,no_run")] -//! snapbox::harness::Harness::new( -//! "tests/fixtures/invalid", -//! setup, -//! test, -//! ) -//! .select(["tests/cases/*.in"]) -//! .action_env("SNAPSHOTS") -//! .test(); -//! -//! fn setup(input_path: std::path::PathBuf) -> snapbox::harness::Case { -//! let name = input_path.file_name().unwrap().to_str().unwrap().to_owned(); -//! let expected = input_path.with_extension("out"); -//! snapbox::harness::Case { -//! name, -//! fixture: input_path, -//! expected, -//! } -//! } -//! -//! fn test(input_path: &std::path::Path) -> Result> { -//! let raw = std::fs::read_to_string(input_path)?; -//! let num = raw.parse::()?; -//! -//! let actual = num + 10; -//! -//! Ok(actual) -//! } -//! ``` -//! //! [trycmd]: https://docs.rs/trycmd #![cfg_attr(docsrs, feature(doc_auto_cfg))] @@ -103,15 +71,9 @@ pub mod cmd; pub mod data; pub mod dir; pub mod filter; -pub mod path; pub mod report; pub mod utils; -#[cfg(feature = "harness")] -pub mod harness; - -#[deprecated(since = "0.5.11", note = "Replaced with `assert::Assert`")] -pub use assert::Action; pub use assert::Assert; pub use data::Data; pub use data::IntoData; @@ -123,17 +85,6 @@ pub use filter::Redactions; #[doc(hidden)] pub use snapbox_macros::debug; -#[deprecated(since = "0.5.11", note = "Replaced with `Redactions`")] -pub type Substitutions = filter::Redactions; - -#[deprecated(since = "0.5.11", note = "Replaced with `assert::DEFAULT_ACTION_ENV`")] -pub const DEFAULT_ACTION_ENV: &str = assert::DEFAULT_ACTION_ENV; - -#[deprecated(since = "0.5.11", note = "Replaced with `assert::Result`")] -pub type Result = std::result::Result; -#[deprecated(since = "0.5.11", note = "Replaced with `assert::Error`")] -pub type Error = assert::Error; - /// Easier access to common traits pub mod prelude { pub use crate::IntoData; @@ -142,71 +93,6 @@ pub mod prelude { pub use crate::ToDebug; } -/// Check if a value is the same as an expected value -/// -/// When the content is text, newlines are normalized. -/// -/// ```rust -/// # use snapbox::assert_eq; -/// let output = "something"; -/// let expected = "something"; -/// assert_eq(expected, output); -/// ``` -/// -/// Can combine this with [`file!`] -/// ```rust,no_run -/// # use snapbox::assert_eq; -/// # use snapbox::file; -/// let actual = "something"; -/// assert_eq(file!["output.txt"], actual); -/// ``` -#[track_caller] -#[deprecated( - since = "0.5.11", - note = "Replaced with `assert_data_eq!(actual, expected.raw())`" -)] -pub fn assert_eq(expected: impl Into, actual: impl Into) { - Assert::new() - .action_env(assert::DEFAULT_ACTION_ENV) - .eq_(actual, expected.into().raw()); -} - -/// Check if a value matches a pattern -/// -/// Pattern syntax: -/// - `...` is a line-wildcard when on a line by itself -/// - `[..]` is a character-wildcard when inside a line -/// - `[EXE]` matches `.exe` on Windows -/// -/// Normalization: -/// - Newlines -/// - `\` to `/` -/// -/// ```rust -/// # use snapbox::assert_matches; -/// let output = "something"; -/// let expected = "so[..]g"; -/// assert_matches(expected, output); -/// ``` -/// -/// Can combine this with [`file!`] -/// ```rust,no_run -/// # use snapbox::assert_matches; -/// # use snapbox::file; -/// let actual = "something"; -/// assert_matches(file!["output.txt"], actual); -/// ``` -#[track_caller] -#[deprecated( - since = "0.5.11", - note = "Replaced with `assert_data_eq!(actual, expected)`" -)] -pub fn assert_matches(pattern: impl Into, actual: impl Into) { - Assert::new() - .action_env(assert::DEFAULT_ACTION_ENV) - .eq_(actual, pattern); -} - /// Check if a path matches the content of another path, recursively /// /// When the content is text, newlines are normalized. diff --git a/crates/snapbox/src/path.rs b/crates/snapbox/src/path.rs deleted file mode 100644 index de357475..00000000 --- a/crates/snapbox/src/path.rs +++ /dev/null @@ -1,48 +0,0 @@ -//! Initialize working directories and assert on how they've changed - -#[doc(inline)] -pub use crate::cargo_rustc_current_dir; -#[doc(inline)] -pub use crate::current_dir; -#[doc(inline)] -pub use crate::current_rs; - -/// Working directory for tests -#[deprecated(since = "0.5.11", note = "Replaced with dir::DirRoot")] -pub type PathFixture = crate::dir::DirRoot; - -pub use crate::dir::FileType; -pub use crate::dir::PathDiff; - -/// Recursively walk a path -/// -/// Note: Ignores `.keep` files -#[deprecated(since = "0.5.11", note = "Replaced with dir::Walk")] -#[cfg(feature = "dir")] -pub type Walk = crate::dir::Walk; - -/// Copy a template into a [`PathFixture`] -/// -/// Note: Generally you'll use [`PathFixture::with_template`] instead. -/// -/// Note: Ignores `.keep` files -#[deprecated(since = "0.5.11", note = "Replaced with dir::copy_template")] -#[cfg(feature = "dir")] -pub fn copy_template( - source: impl AsRef, - dest: impl AsRef, -) -> crate::assert::Result<()> { - crate::dir::copy_template(source, dest) -} - -#[deprecated(since = "0.5.11", note = "Replaced with dir::resolve_dir")] -pub fn resolve_dir( - path: impl AsRef, -) -> Result { - crate::dir::resolve_dir(path) -} - -#[deprecated(since = "0.5.11", note = "Replaced with dir::strip_trailing_slash")] -pub fn strip_trailing_slash(path: &std::path::Path) -> &std::path::Path { - crate::dir::strip_trailing_slash(path) -} diff --git a/crates/snapbox/src/report/color.rs b/crates/snapbox/src/report/color.rs index 3df14402..85bcac23 100644 --- a/crates/snapbox/src/report/color.rs +++ b/crates/snapbox/src/report/color.rs @@ -28,28 +28,6 @@ impl Palette { Self::default() } - #[deprecated(since = "0.4.9", note = "Renamed to `Palette::color")] - pub fn always() -> Self { - Self::color() - } - - #[deprecated(since = "0.4.9", note = "Renamed to `Palette::plain")] - pub fn never() -> Self { - Self::plain() - } - - #[deprecated( - since = "0.4.9", - note = "Use `Palette::always`, `auto` behavior is now implicit" - )] - pub fn auto() -> Self { - if is_colored() { - Self::color() - } else { - Self::plain() - } - } - pub fn info(self, item: D) -> Styled { Styled::new(item, self.info) } @@ -75,17 +53,6 @@ impl Palette { } } -fn is_colored() -> bool { - #[cfg(feature = "color")] - { - anstream::AutoStream::choice(&std::io::stderr()) != anstream::ColorChoice::Never - } - #[cfg(not(feature = "color"))] - { - false - } -} - pub(crate) use anstyle::Style; #[derive(Debug)] diff --git a/crates/snapbox/src/utils/mod.rs b/crates/snapbox/src/utils/mod.rs index 2dbb862e..8f3a65af 100644 --- a/crates/snapbox/src/utils/mod.rs +++ b/crates/snapbox/src/utils/mod.rs @@ -8,27 +8,3 @@ pub use crate::cargo_rustc_current_dir; pub use crate::current_dir; #[doc(inline)] pub use crate::current_rs; - -#[deprecated(since = "0.5.11", note = "Replaced with `filter::normalize_lines`")] -pub fn normalize_lines(data: &str) -> String { - crate::filter::normalize_lines(data) -} - -#[deprecated(since = "0.5.11", note = "Replaced with `filter::normalize_paths`")] -pub fn normalize_paths(data: &str) -> String { - crate::filter::normalize_paths(data) -} - -/// "Smart" text normalization -/// -/// This includes -/// - Line endings -/// - Path separators -#[deprecated( - since = "0.5.11", - note = "Replaced with `filter::normalize_paths(filter::normalize_lines(...))`" -)] -pub fn normalize_text(data: &str) -> String { - #[allow(deprecated)] - normalize_paths(&normalize_lines(data)) -}