Skip to content

Commit

Permalink
Merge pull request #329 from epage/break
Browse files Browse the repository at this point in the history
fix(snap)!: Re-integrate breaking changes
  • Loading branch information
epage authored May 23, 2024
2 parents 57a47c8 + a9cc0e4 commit 7269940
Show file tree
Hide file tree
Showing 23 changed files with 729 additions and 971 deletions.
3 changes: 1 addition & 2 deletions Cargo.lock

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

8 changes: 3 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 All @@ -44,6 +42,8 @@ path = ["dir"]
cmd = ["dep:os_pipe", "dep:wait-timeout", "dep:libc", "dep:windows-sys"]
## Building of examples for snapshotting
examples = ["dep:escargot"]
## Regex text substitutions
regex = ["dep:regex"]

## Snapshotting of json
json = ["structured-data", "dep:serde_json", "dep:serde"]
Expand Down Expand Up @@ -71,9 +71,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 All @@ -97,6 +94,7 @@ document-features = { version = "0.2.6", optional = true }
serde_json = { version = "1.0.85", optional = true}
anstyle-svg = { version = "0.1.3", optional = true }
serde = { version = "1.0.198", optional = true }
regex = { version = "1.10.4", optional = true, default-features = false, features = ["std"] }

[target.'cfg(windows)'.dependencies]
windows-sys = { version = "0.52.0", features = ["Win32_Foundation"], optional = true }
Expand Down
79 changes: 9 additions & 70 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 All @@ -49,6 +49,8 @@ impl Assert {
/// - `...` is a line-wildcard when on a line by itself
/// - `[..]` is a character-wildcard when inside a line
/// - `[EXE]` matches `.exe` on Windows
/// - `"{...}"` is a JSON value wildcard
/// - `"...": "{...}"` is a JSON key-value wildcard
/// - `\` to `/`
/// - Newlines
///
Expand All @@ -60,92 +62,29 @@ 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();
}
}

/// 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();
}
#[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(
Expand Down
156 changes: 16 additions & 140 deletions crates/snapbox/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,8 @@ impl OutputAssert {
/// - `...` is a line-wildcard when on a line by itself
/// - `[..]` is a character-wildcard when inside a line
/// - `[EXE]` matches `.exe` on Windows
/// - `"{...}"` is a JSON value wildcard
/// - `"...": "{...}"` is a JSON key-value wildcard
/// - `\` to `/`
/// - Newlines
///
Expand All @@ -609,7 +611,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,82 +624,18 @@ 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)
}

/// 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)
#[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]
Expand All @@ -716,6 +654,8 @@ impl OutputAssert {
/// - `...` is a line-wildcard when on a line by itself
/// - `[..]` is a character-wildcard when inside a line
/// - `[EXE]` matches `.exe` on Windows
/// - `"{...}"` is a JSON value wildcard
/// - `"...": "{...}"` is a JSON key-value wildcard
/// - `\` to `/`
/// - Newlines
///
Expand All @@ -731,7 +671,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 @@ -744,82 +684,18 @@ 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)
}

/// 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)
#[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]
Expand Down
Loading

0 comments on commit 7269940

Please sign in to comment.