Skip to content

Commit 7269940

Browse files
authored
Merge pull request #329 from epage/break
fix(snap)!: Re-integrate breaking changes
2 parents 57a47c8 + a9cc0e4 commit 7269940

File tree

23 files changed

+729
-971
lines changed

23 files changed

+729
-971
lines changed

Cargo.lock

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/snapbox/Cargo.toml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ default = ["color-auto", "diff"]
3232

3333
#! Feature Flags
3434

35-
## Simple input/output test harness
36-
harness = ["dep:libtest-mimic", "dep:ignore"]
3735
## Smarter binary file detection
3836
detect-encoding = ["dep:content_inspector"]
3937
## Snapshotting of directories
@@ -44,6 +42,8 @@ path = ["dir"]
4442
cmd = ["dep:os_pipe", "dep:wait-timeout", "dep:libc", "dep:windows-sys"]
4543
## Building of examples for snapshotting
4644
examples = ["dep:escargot"]
45+
## Regex text substitutions
46+
regex = ["dep:regex"]
4747

4848
## Snapshotting of json
4949
json = ["structured-data", "dep:serde_json", "dep:serde"]
@@ -71,9 +71,6 @@ name = "snap-fixture" # For `snapbox`s tests only
7171
normalize-line-endings = "0.3.0"
7272
snapbox-macros = { path = "../snapbox-macros", version = "0.3.9" }
7373

74-
libtest-mimic = { version = "0.7.0", optional = true }
75-
ignore = { version = "0.4", optional = true }
76-
7774
content_inspector = { version = "0.2.4", optional = true }
7875

7976
tempfile = { version = "3.0", optional = true }
@@ -97,6 +94,7 @@ document-features = { version = "0.2.6", optional = true }
9794
serde_json = { version = "1.0.85", optional = true}
9895
anstyle-svg = { version = "0.1.3", optional = true }
9996
serde = { version = "1.0.198", optional = true }
97+
regex = { version = "1.10.4", optional = true, default-features = false, features = ["std"] }
10098

10199
[target.'cfg(windows)'.dependencies]
102100
windows-sys = { version = "0.52.0", features = ["Win32_Foundation"], optional = true }

crates/snapbox/src/assert/mod.rs

Lines changed: 9 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub use error::Result;
2626
/// # use snapbox::Assert;
2727
/// # use snapbox::file;
2828
/// let actual = "something";
29-
/// Assert::new().eq_(actual, file!["output.txt"]);
29+
/// Assert::new().eq(actual, file!["output.txt"]);
3030
/// ```
3131
#[derive(Clone, Debug)]
3232
pub struct Assert {
@@ -49,6 +49,8 @@ impl Assert {
4949
/// - `...` is a line-wildcard when on a line by itself
5050
/// - `[..]` is a character-wildcard when inside a line
5151
/// - `[EXE]` matches `.exe` on Windows
52+
/// - `"{...}"` is a JSON value wildcard
53+
/// - `"...": "{...}"` is a JSON key-value wildcard
5254
/// - `\` to `/`
5355
/// - Newlines
5456
///
@@ -60,92 +62,29 @@ impl Assert {
6062
/// # use snapbox::Assert;
6163
/// let actual = "something";
6264
/// let expected = "so[..]g";
63-
/// Assert::new().eq_(actual, expected);
65+
/// Assert::new().eq(actual, expected);
6466
/// ```
6567
///
6668
/// Can combine this with [`file!`][crate::file]
6769
/// ```rust,no_run
6870
/// # use snapbox::Assert;
6971
/// # use snapbox::file;
7072
/// let actual = "something";
71-
/// Assert::new().eq_(actual, file!["output.txt"]);
73+
/// Assert::new().eq(actual, file!["output.txt"]);
7274
/// ```
7375
#[track_caller]
74-
pub fn eq_(&self, actual: impl IntoData, expected: impl IntoData) {
76+
pub fn eq(&self, actual: impl IntoData, expected: impl IntoData) {
7577
let expected = expected.into_data();
7678
let actual = actual.into_data();
7779
if let Err(err) = self.try_eq(Some(&"In-memory"), actual, expected) {
7880
err.panic();
7981
}
8082
}
8183

82-
/// Check if a value is the same as an expected value
83-
///
84-
/// When the content is text, newlines are normalized.
85-
///
86-
/// ```rust
87-
/// # use snapbox::Assert;
88-
/// let actual = "something";
89-
/// let expected = "something";
90-
/// Assert::new().eq(expected, actual);
91-
/// ```
92-
///
93-
/// Can combine this with [`file!`][crate::file]
94-
/// ```rust,no_run
95-
/// # use snapbox::Assert;
96-
/// # use snapbox::file;
97-
/// let actual = "something";
98-
/// Assert::new().eq(file!["output.txt"], actual);
99-
/// ```
10084
#[track_caller]
101-
#[deprecated(
102-
since = "0.5.11",
103-
note = "Replaced with `Assert::eq_(actual, expected.raw())`"
104-
)]
105-
pub fn eq(&self, expected: impl Into<crate::Data>, actual: impl Into<crate::Data>) {
106-
let expected = expected.into();
107-
let actual = actual.into();
108-
if let Err(err) = self.try_eq(Some(&"In-memory"), actual, expected.raw()) {
109-
err.panic();
110-
}
111-
}
112-
113-
/// Check if a value matches a pattern
114-
///
115-
/// Pattern syntax:
116-
/// - `...` is a line-wildcard when on a line by itself
117-
/// - `[..]` is a character-wildcard when inside a line
118-
/// - `[EXE]` matches `.exe` on Windows
119-
///
120-
/// Normalization:
121-
/// - Newlines
122-
/// - `\` to `/`
123-
///
124-
/// ```rust
125-
/// # use snapbox::Assert;
126-
/// let actual = "something";
127-
/// let expected = "so[..]g";
128-
/// Assert::new().matches(expected, actual);
129-
/// ```
130-
///
131-
/// Can combine this with [`file!`][crate::file]
132-
/// ```rust,no_run
133-
/// # use snapbox::Assert;
134-
/// # use snapbox::file;
135-
/// let actual = "something";
136-
/// Assert::new().matches(file!["output.txt"], actual);
137-
/// ```
138-
#[track_caller]
139-
#[deprecated(
140-
since = "0.5.11",
141-
note = "Replaced with `Assert::eq_(actual, expected)`"
142-
)]
143-
pub fn matches(&self, pattern: impl Into<crate::Data>, actual: impl Into<crate::Data>) {
144-
let pattern = pattern.into();
145-
let actual = actual.into();
146-
if let Err(err) = self.try_eq(Some(&"In-memory"), actual, pattern) {
147-
err.panic();
148-
}
85+
#[deprecated(since = "0.6.0", note = "Replaced with `Assert::eq`")]
86+
pub fn eq_(&self, actual: impl IntoData, expected: impl IntoData) {
87+
self.eq(actual, expected)
14988
}
15089

15190
pub fn try_eq(

crates/snapbox/src/cmd.rs

Lines changed: 16 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,8 @@ impl OutputAssert {
594594
/// - `...` is a line-wildcard when on a line by itself
595595
/// - `[..]` is a character-wildcard when inside a line
596596
/// - `[EXE]` matches `.exe` on Windows
597+
/// - `"{...}"` is a JSON value wildcard
598+
/// - `"...": "{...}"` is a JSON key-value wildcard
597599
/// - `\` to `/`
598600
/// - Newlines
599601
///
@@ -609,7 +611,7 @@ impl OutputAssert {
609611
/// .env("stdout", "hello")
610612
/// .env("stderr", "world")
611613
/// .assert()
612-
/// .stdout_eq_("he[..]o");
614+
/// .stdout_eq("he[..]o");
613615
/// ```
614616
///
615617
/// Can combine this with [`file!`][crate::file]
@@ -622,82 +624,18 @@ impl OutputAssert {
622624
/// .env("stdout", "hello")
623625
/// .env("stderr", "world")
624626
/// .assert()
625-
/// .stdout_eq_(file!["stdout.log"]);
627+
/// .stdout_eq(file!["stdout.log"]);
626628
/// ```
627629
#[track_caller]
628-
pub fn stdout_eq_(self, expected: impl IntoData) -> Self {
630+
pub fn stdout_eq(self, expected: impl IntoData) -> Self {
629631
let expected = expected.into_data();
630632
self.stdout_eq_inner(expected)
631633
}
632634

633-
/// Ensure the command wrote the expected data to `stdout`.
634-
///
635-
/// ```rust,no_run
636-
/// use snapbox::cmd::Command;
637-
/// use snapbox::cmd::cargo_bin;
638-
///
639-
/// let assert = Command::new(cargo_bin("snap-fixture"))
640-
/// .env("stdout", "hello")
641-
/// .env("stderr", "world")
642-
/// .assert()
643-
/// .stdout_eq("hello");
644-
/// ```
645-
///
646-
/// Can combine this with [`file!`][crate::file]
647-
/// ```rust,no_run
648-
/// use snapbox::cmd::Command;
649-
/// use snapbox::cmd::cargo_bin;
650-
/// use snapbox::file;
651-
///
652-
/// let assert = Command::new(cargo_bin("snap-fixture"))
653-
/// .env("stdout", "hello")
654-
/// .env("stderr", "world")
655-
/// .assert()
656-
/// .stdout_eq(file!["stdout.log"]);
657-
/// ```
658-
#[track_caller]
659-
#[deprecated(
660-
since = "0.5.11",
661-
note = "Replaced with `OutputAssert::stdout_eq_(expected.raw())`"
662-
)]
663-
pub fn stdout_eq(self, expected: impl Into<crate::Data>) -> Self {
664-
let expected = expected.into();
665-
self.stdout_eq_inner(expected.raw())
666-
}
667-
668-
/// Ensure the command wrote the expected data to `stdout`.
669-
///
670-
/// ```rust,no_run
671-
/// use snapbox::cmd::Command;
672-
/// use snapbox::cmd::cargo_bin;
673-
///
674-
/// let assert = Command::new(cargo_bin("snap-fixture"))
675-
/// .env("stdout", "hello")
676-
/// .env("stderr", "world")
677-
/// .assert()
678-
/// .stdout_matches("he[..]o");
679-
/// ```
680-
///
681-
/// Can combine this with [`file!`][crate::file]
682-
/// ```rust,no_run
683-
/// use snapbox::cmd::Command;
684-
/// use snapbox::cmd::cargo_bin;
685-
/// use snapbox::file;
686-
///
687-
/// let assert = Command::new(cargo_bin("snap-fixture"))
688-
/// .env("stdout", "hello")
689-
/// .env("stderr", "world")
690-
/// .assert()
691-
/// .stdout_matches(file!["stdout.log"]);
692-
/// ```
693635
#[track_caller]
694-
#[deprecated(
695-
since = "0.5.11",
696-
note = "Replaced with `OutputAssert::stdout_eq_(expected)`"
697-
)]
698-
pub fn stdout_matches(self, expected: impl Into<crate::Data>) -> Self {
699-
let expected = expected.into();
700-
self.stdout_eq_inner(expected)
636+
#[deprecated(since = "0.6.0", note = "Replaced with `OutputAssert::stdout_eq`")]
637+
pub fn stdout_eq_(self, expected: impl IntoData) -> Self {
638+
self.stdout_eq(expected)
701639
}
702640

703641
#[track_caller]
@@ -716,6 +654,8 @@ impl OutputAssert {
716654
/// - `...` is a line-wildcard when on a line by itself
717655
/// - `[..]` is a character-wildcard when inside a line
718656
/// - `[EXE]` matches `.exe` on Windows
657+
/// - `"{...}"` is a JSON value wildcard
658+
/// - `"...": "{...}"` is a JSON key-value wildcard
719659
/// - `\` to `/`
720660
/// - Newlines
721661
///
@@ -731,7 +671,7 @@ impl OutputAssert {
731671
/// .env("stdout", "hello")
732672
/// .env("stderr", "world")
733673
/// .assert()
734-
/// .stderr_eq_("wo[..]d");
674+
/// .stderr_eq("wo[..]d");
735675
/// ```
736676
///
737677
/// Can combine this with [`file!`][crate::file]
@@ -744,82 +684,18 @@ impl OutputAssert {
744684
/// .env("stdout", "hello")
745685
/// .env("stderr", "world")
746686
/// .assert()
747-
/// .stderr_eq_(file!["stderr.log"]);
687+
/// .stderr_eq(file!["stderr.log"]);
748688
/// ```
749689
#[track_caller]
750-
pub fn stderr_eq_(self, expected: impl IntoData) -> Self {
690+
pub fn stderr_eq(self, expected: impl IntoData) -> Self {
751691
let expected = expected.into_data();
752692
self.stderr_eq_inner(expected)
753693
}
754694

755-
/// Ensure the command wrote the expected data to `stderr`.
756-
///
757-
/// ```rust,no_run
758-
/// use snapbox::cmd::Command;
759-
/// use snapbox::cmd::cargo_bin;
760-
///
761-
/// let assert = Command::new(cargo_bin("snap-fixture"))
762-
/// .env("stdout", "hello")
763-
/// .env("stderr", "world")
764-
/// .assert()
765-
/// .stderr_eq("world");
766-
/// ```
767-
///
768-
/// Can combine this with [`file!`][crate::file]
769-
/// ```rust,no_run
770-
/// use snapbox::cmd::Command;
771-
/// use snapbox::cmd::cargo_bin;
772-
/// use snapbox::file;
773-
///
774-
/// let assert = Command::new(cargo_bin("snap-fixture"))
775-
/// .env("stdout", "hello")
776-
/// .env("stderr", "world")
777-
/// .assert()
778-
/// .stderr_eq(file!["stderr.log"]);
779-
/// ```
780-
#[track_caller]
781-
#[deprecated(
782-
since = "0.5.11",
783-
note = "Replaced with `OutputAssert::stderr_eq_(expected.raw())`"
784-
)]
785-
pub fn stderr_eq(self, expected: impl Into<crate::Data>) -> Self {
786-
let expected = expected.into();
787-
self.stderr_eq_inner(expected.raw())
788-
}
789-
790-
/// Ensure the command wrote the expected data to `stderr`.
791-
///
792-
/// ```rust,no_run
793-
/// use snapbox::cmd::Command;
794-
/// use snapbox::cmd::cargo_bin;
795-
///
796-
/// let assert = Command::new(cargo_bin("snap-fixture"))
797-
/// .env("stdout", "hello")
798-
/// .env("stderr", "world")
799-
/// .assert()
800-
/// .stderr_matches("wo[..]d");
801-
/// ```
802-
///
803-
/// Can combine this with [`file!`][crate::file]
804-
/// ```rust,no_run
805-
/// use snapbox::cmd::Command;
806-
/// use snapbox::cmd::cargo_bin;
807-
/// use snapbox::file;
808-
///
809-
/// let assert = Command::new(cargo_bin("snap-fixture"))
810-
/// .env("stdout", "hello")
811-
/// .env("stderr", "world")
812-
/// .assert()
813-
/// .stderr_matches(file!["stderr.log"]);
814-
/// ```
815695
#[track_caller]
816-
#[deprecated(
817-
since = "0.5.11",
818-
note = "Replaced with `OutputAssert::stderr_eq_(expected)`"
819-
)]
820-
pub fn stderr_matches(self, expected: impl Into<crate::Data>) -> Self {
821-
let expected = expected.into();
822-
self.stderr_eq_inner(expected)
696+
#[deprecated(since = "0.6.0", note = "Replaced with `OutputAssert::stderr_eq`")]
697+
pub fn stderr_eq_(self, expected: impl IntoData) -> Self {
698+
self.stderr_eq(expected)
823699
}
824700

825701
#[track_caller]

0 commit comments

Comments
 (0)