Skip to content

Commit

Permalink
refactor(snap): Switch to IntoData for easier discoverability
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Apr 22, 2024
1 parent 00e746b commit e1cadb3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
7 changes: 4 additions & 3 deletions crates/snapbox/src/assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::io::stderr;

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

/// Snapshot assertion against a file's contents
///
Expand Down Expand Up @@ -61,9 +62,9 @@ impl Assert {
/// Assert::new().eq(file!["output.txt"], actual);
/// ```
#[track_caller]
pub fn eq(&self, expected: impl Into<crate::Data>, actual: impl Into<crate::Data>) {
let expected = expected.into();
let actual = actual.into();
pub fn eq(&self, expected: impl IntoData, actual: impl IntoData) {
let expected = expected.into_data();
let actual = actual.into_data();
if let Err(err) = self.try_eq(expected, actual, Some(&"In-memory")) {
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 @@ -621,8 +623,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 @@ -671,8 +673,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
2 changes: 1 addition & 1 deletion crates/snapbox/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ pub mod prelude {
/// assert_eq(file!["output.txt"], actual);
/// ```
#[track_caller]
pub fn assert_eq(expected: impl Into<crate::Data>, actual: impl Into<crate::Data>) {
pub fn assert_eq(expected: impl IntoData, actual: impl IntoData) {
Assert::new()
.action_env(DEFAULT_ACTION_ENV)
.eq(expected, actual);
Expand Down

0 comments on commit e1cadb3

Please sign in to comment.