Skip to content

Commit

Permalink
fix(snap)!: Remove deprecated APIs
Browse files Browse the repository at this point in the history
Cherry pick 86fa504 (assert-rs#275)
Cherry pick 3ddd841 (assert-rs#290)
  • Loading branch information
epage committed May 23, 2024
1 parent 57a47c8 commit c06fa94
Show file tree
Hide file tree
Showing 14 changed files with 8 additions and 700 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions crates/snapbox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }
Expand Down
69 changes: 0 additions & 69 deletions crates/snapbox/src/assert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<crate::Data>, actual: impl Into<crate::Data>) {
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<crate::Data>, actual: impl Into<crate::Data>) {
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>,
Expand Down
140 changes: 0 additions & 140 deletions crates/snapbox/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<crate::Data>) -> 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<crate::Data>) -> 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();
Expand Down Expand Up @@ -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<crate::Data>) -> 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<crate::Data>) -> 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();
Expand Down
16 changes: 0 additions & 16 deletions crates/snapbox/src/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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`.
Expand Down
24 changes: 0 additions & 24 deletions crates/snapbox/src/data/normalize.rs

This file was deleted.

27 changes: 0 additions & 27 deletions crates/snapbox/src/data/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
Loading

0 comments on commit c06fa94

Please sign in to comment.