Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(snap)!: Re-integrate breaking changes #329

Merged
merged 28 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c06fa94
fix(snap)!: Remove deprecated APIs
epage May 17, 2024
afadbca
fix(snap): Deprecate eq_ in favor of eq fn's
epage May 17, 2024
ffca2b6
fix(snap)!: Remove indent support
epage Apr 18, 2024
0b77043
fix(snap)!: Include a trailing newline in snapshots
epage Apr 18, 2024
70bcbd0
fix(snap)!: Allow adding formats without breaking compatibility
epage Apr 19, 2024
7b9f98b
feat(snap): Jsonlines support
epage Apr 19, 2024
264cd35
test(snap): Verify data formats
epage Apr 19, 2024
2682c53
fix(snap): Change how we normalize matches
epage Apr 19, 2024
ea6f146
fix(filter)!: Allow additional redacted value types
epage May 20, 2024
3570cc3
feat(filter): Allow regexes for substitutions
epage Apr 19, 2024
e3e5813
docs(filter): Improve Redactions docs
epage May 20, 2024
4a8e317
feat(filters): Allow paths as redacted values
epage Apr 22, 2024
0a50353
fix(filters)!: Dont normalize all redactions
epage Apr 22, 2024
4026b9a
refactor(filter): Simplify Redactions
epage May 20, 2024
1d52e24
fix(data)!: Clarify what types are supported
epage May 20, 2024
b332ee4
refactor(filter): Clarify variable names
epage May 20, 2024
763bb2d
test(filter): Show overlapping redactions problem
epage May 20, 2024
1229d33
fix(filter): Prioritize more-specific (longer, non-regex) Redactions
epage May 20, 2024
c178cf8
test(filter): Show incomplete redacting on json
epage May 20, 2024
2cba34f
fix(filter): Still redact json values on mismatch
epage May 20, 2024
71c99cf
test(filter): Show object key filtering
epage May 20, 2024
1a21cc2
fix(filter)!: Apply basic filters to json keys
epage May 20, 2024
ed482c3
test(filter): Show redactions not applying to keys
epage May 20, 2024
23bad1f
fix(filter)!: Redact json keys
epage May 20, 2024
7f4b5da
test(filter): Show lack of key wildcard
epage May 20, 2024
9a873fa
docs(filter): Cover json value wildcard
epage May 20, 2024
4c1e2c0
feat(filter)!: Allow key wildcards
epage May 20, 2024
a9cc0e4
feat(filter): Expose Redactions::redact
epage May 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading