Skip to content

Commit

Permalink
fix(assert): Use IntoData for better discoverability
Browse files Browse the repository at this point in the history
Not a breaking change because these calls were added in assert-rs#318

Cherry pick e1cadb3 (assert-rs#292)
  • Loading branch information
epage committed May 17, 2024
1 parent ebcff2a commit 2e7258b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
7 changes: 4 additions & 3 deletions crates/snapbox/src/assert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use anstream::stderr;
use std::io::stderr;

use crate::filter::{Filter as _, FilterNewlines, FilterPaths, FilterRedactions};
use crate::IntoData;

pub use action::Action;
pub use action::DEFAULT_ACTION_ENV;
Expand Down Expand Up @@ -70,9 +71,9 @@ impl Assert {
/// Assert::new().eq_(actual, file!["output.txt"]);
/// ```
#[track_caller]
pub fn eq_(&self, actual: impl Into<crate::Data>, expected: impl Into<crate::Data>) {
let expected = expected.into();
let actual = actual.into();
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();
}
Expand Down
14 changes: 8 additions & 6 deletions crates/snapbox/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#[cfg(feature = "color")]
use anstream::panic;

use crate::IntoData;

/// Process spawning for testing of non-interactive commands
#[derive(Debug)]
pub struct Command {
Expand Down Expand Up @@ -243,8 +245,8 @@ impl Command {
/// .assert()
/// .stdout_eq("42");
/// ```
pub fn stdin(mut self, stream: impl Into<crate::Data>) -> Self {
self.stdin = Some(stream.into());
pub fn stdin(mut self, stream: impl IntoData) -> Self {
self.stdin = Some(stream.into_data());
self
}

Expand Down Expand Up @@ -623,8 +625,8 @@ impl OutputAssert {
/// .stdout_eq_(file!["stdout.log"]);
/// ```
#[track_caller]
pub fn stdout_eq_(self, expected: impl Into<crate::Data>) -> Self {
let expected = expected.into();
pub fn stdout_eq_(self, expected: impl IntoData) -> Self {
let expected = expected.into_data();
self.stdout_eq_inner(expected)
}

Expand Down Expand Up @@ -745,8 +747,8 @@ impl OutputAssert {
/// .stderr_eq_(file!["stderr.log"]);
/// ```
#[track_caller]
pub fn stderr_eq_(self, expected: impl Into<crate::Data>) -> Self {
let expected = expected.into();
pub fn stderr_eq_(self, expected: impl IntoData) -> Self {
let expected = expected.into_data();
self.stderr_eq_inner(expected)
}

Expand Down

0 comments on commit 2e7258b

Please sign in to comment.