Skip to content

Commit

Permalink
fix(snap): Deprecate eq_ in favor of eq fn's
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed May 23, 2024
1 parent c06fa94 commit afadbca
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 13 deletions.
14 changes: 10 additions & 4 deletions crates/snapbox/src/assert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub use error::Result;
/// # use snapbox::Assert;
/// # use snapbox::file;
/// let actual = "something";
/// Assert::new().eq_(actual, file!["output.txt"]);
/// Assert::new().eq(actual, file!["output.txt"]);
/// ```
#[derive(Clone, Debug)]
pub struct Assert {
Expand Down Expand Up @@ -60,25 +60,31 @@ impl Assert {
/// # use snapbox::Assert;
/// let actual = "something";
/// let expected = "so[..]g";
/// Assert::new().eq_(actual, expected);
/// Assert::new().eq(actual, expected);
/// ```
///
/// Can combine this with [`file!`][crate::file]
/// ```rust,no_run
/// # use snapbox::Assert;
/// # use snapbox::file;
/// let actual = "something";
/// Assert::new().eq_(actual, file!["output.txt"]);
/// Assert::new().eq(actual, file!["output.txt"]);
/// ```
#[track_caller]
pub fn eq_(&self, actual: impl IntoData, expected: impl IntoData) {
pub fn eq(&self, actual: impl IntoData, expected: impl IntoData) {
let expected = expected.into_data();
let actual = actual.into_data();
if let Err(err) = self.try_eq(Some(&"In-memory"), actual, expected) {
err.panic();
}
}

#[track_caller]
#[deprecated(since = "0.6.0", note = "Replaced with `Assert::eq`")]
pub fn eq_(&self, actual: impl IntoData, expected: impl IntoData) {
self.eq(actual, expected)
}

pub fn try_eq(
&self,
actual_name: Option<&dyn std::fmt::Display>,
Expand Down
24 changes: 18 additions & 6 deletions crates/snapbox/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ impl OutputAssert {
/// .env("stdout", "hello")
/// .env("stderr", "world")
/// .assert()
/// .stdout_eq_("he[..]o");
/// .stdout_eq("he[..]o");
/// ```
///
/// Can combine this with [`file!`][crate::file]
Expand All @@ -622,14 +622,20 @@ impl OutputAssert {
/// .env("stdout", "hello")
/// .env("stderr", "world")
/// .assert()
/// .stdout_eq_(file!["stdout.log"]);
/// .stdout_eq(file!["stdout.log"]);
/// ```
#[track_caller]
pub fn stdout_eq_(self, expected: impl IntoData) -> Self {
pub fn stdout_eq(self, expected: impl IntoData) -> Self {
let expected = expected.into_data();
self.stdout_eq_inner(expected)
}

#[track_caller]
#[deprecated(since = "0.6.0", note = "Replaced with `OutputAssert::stdout_eq`")]
pub fn stdout_eq_(self, expected: impl IntoData) -> Self {
self.stdout_eq(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 @@ -661,7 +667,7 @@ impl OutputAssert {
/// .env("stdout", "hello")
/// .env("stderr", "world")
/// .assert()
/// .stderr_eq_("wo[..]d");
/// .stderr_eq("wo[..]d");
/// ```
///
/// Can combine this with [`file!`][crate::file]
Expand All @@ -674,14 +680,20 @@ impl OutputAssert {
/// .env("stdout", "hello")
/// .env("stderr", "world")
/// .assert()
/// .stderr_eq_(file!["stderr.log"]);
/// .stderr_eq(file!["stderr.log"]);
/// ```
#[track_caller]
pub fn stderr_eq_(self, expected: impl IntoData) -> Self {
pub fn stderr_eq(self, expected: impl IntoData) -> Self {
let expected = expected.into_data();
self.stderr_eq_inner(expected)
}

#[track_caller]
#[deprecated(since = "0.6.0", note = "Replaced with `OutputAssert::stderr_eq`")]
pub fn stderr_eq_(self, expected: impl IntoData) -> Self {
self.stderr_eq(expected)
}

#[track_caller]
fn stderr_eq_inner(self, expected: crate::Data) -> Self {
let actual = self.output.stderr.as_slice().into_data();
Expand Down
2 changes: 1 addition & 1 deletion crates/snapbox/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
//! let actual = "...";
//! snapbox::Assert::new()
//! .action_env("SNAPSHOTS")
//! .eq_(actual, snapbox::file!["help_output_is_clean.txt"]);
//! .eq(actual, snapbox::file!["help_output_is_clean.txt"]);
//! ```
//!
//! [trycmd]: https://docs.rs/trycmd
Expand Down
2 changes: 1 addition & 1 deletion crates/snapbox/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ macro_rules! assert_data_eq {
let expected = $crate::IntoData::into_data($expected);
$crate::Assert::new()
.action_env($crate::assert::DEFAULT_ACTION_ENV)
.eq_(actual, expected);
.eq(actual, expected);
}};
}

Expand Down
2 changes: 1 addition & 1 deletion crates/trycmd/tests/testsuite/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ fn dump_schema() {
snapbox::cmd::Command::new(bin_path)
.assert()
.success()
.stdout_eq_(snapbox::file!["../../schema.json"]);
.stdout_eq(snapbox::file!["../../schema.json"]);
}

0 comments on commit afadbca

Please sign in to comment.