Skip to content

Commit 11d0002

Browse files
committed
Auto merge of #13963 - epage:snapbox, r=weihanglo
chore: Update to snapbox 0.6 ### What does this PR try to resolve? This unblocks regex redactions which will help with `Finished in 3.45s` messages as well as maybe switching away from `compare.rs` generally. ### How should we test and review this PR? ### Additional information
2 parents 95eeafa + 9af864e commit 11d0002

File tree

284 files changed

+606
-601
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

284 files changed

+606
-601
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ sha1 = "0.10.6"
9191
sha2 = "0.10.8"
9292
shell-escape = "0.1.5"
9393
supports-hyperlinks = "3.0.0"
94-
snapbox = { version = "0.5.9", features = ["diff", "path", "term-svg"] }
94+
snapbox = { version = "0.6.5", features = ["diff", "dir", "term-svg"] }
9595
tar = { version = "0.4.40", default-features = false }
9696
tempfile = "3.10.1"
9797
thiserror = "1.0.59"

crates/cargo-test-support/src/compare.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,15 @@ pub fn assert_ui() -> snapbox::Assert {
8080
// Use `from_file_path` instead of `from_dir_path` so the trailing slash is
8181
// put in the users output, rather than hidden in the variable
8282
let root_url = url::Url::from_file_path(&root).unwrap().to_string();
83-
let root = root.display().to_string();
8483

85-
let mut subs = snapbox::Substitutions::new();
86-
subs.extend([
87-
(
88-
"[EXE]",
89-
std::borrow::Cow::Borrowed(std::env::consts::EXE_SUFFIX),
90-
),
91-
("[ROOT]", std::borrow::Cow::Owned(root)),
92-
("[ROOTURL]", std::borrow::Cow::Owned(root_url)),
93-
])
94-
.unwrap();
84+
let mut subs = snapbox::Redactions::new();
85+
subs.extend([("[EXE]", std::env::consts::EXE_SUFFIX)])
86+
.unwrap();
87+
subs.insert("[ROOT]", root).unwrap();
88+
subs.insert("[ROOTURL]", root_url).unwrap();
9589
snapbox::Assert::new()
96-
.action_env(snapbox::DEFAULT_ACTION_ENV)
97-
.substitutions(subs)
90+
.action_env(snapbox::assert::DEFAULT_ACTION_ENV)
91+
.redact_with(subs)
9892
}
9993

10094
/// Normalizes the output so that it can be compared against the expected value.

crates/cargo-test-support/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ macro_rules! t {
4040
}
4141

4242
pub use snapbox::file;
43-
pub use snapbox::path::current_dir;
4443
pub use snapbox::str;
44+
pub use snapbox::utils::current_dir;
4545

4646
#[track_caller]
4747
pub fn panic_error(what: &str, err: impl Into<anyhow::Error>) -> ! {
@@ -315,7 +315,7 @@ impl Project {
315315
pub fn from_template(template_path: impl AsRef<std::path::Path>) -> Self {
316316
let root = paths::root();
317317
let project_root = root.join("case");
318-
snapbox::path::copy_template(template_path.as_ref(), &project_root).unwrap();
318+
snapbox::dir::copy_template(template_path.as_ref(), &project_root).unwrap();
319319
Self { root: project_root }
320320
}
321321

crates/cargo-util-schemas/src/core/partial_version.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ enum ErrorKind {
186186
#[cfg(test)]
187187
mod test {
188188
use super::*;
189+
use snapbox::prelude::*;
189190
use snapbox::str;
190191

191192
#[test]
@@ -202,7 +203,7 @@ mod test {
202203
Ok(result) => result.to_string(),
203204
Err(err) => format!("didn't pass: {err}"),
204205
};
205-
snapbox::assert_eq(expected.clone(), actual);
206+
snapbox::assert_data_eq!(actual, expected.clone().raw());
206207
}
207208
}
208209

@@ -241,7 +242,7 @@ mod test {
241242
Ok(result) => format!("didn't fail: {result:?}"),
242243
Err(err) => err.to_string(),
243244
};
244-
snapbox::assert_eq(expected.clone(), actual);
245+
snapbox::assert_data_eq!(actual, expected.clone().raw());
245246
}
246247
}
247248
}

crates/cargo-util-schemas/src/manifest/rust_version.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ enum RustVersionErrorKind {
106106
#[cfg(test)]
107107
mod test {
108108
use super::*;
109+
use snapbox::prelude::*;
109110
use snapbox::str;
110111

111112
#[test]
@@ -212,7 +213,7 @@ mod test {
212213
Ok(result) => format!("didn't fail: {result:?}"),
213214
Err(err) => err.to_string(),
214215
};
215-
snapbox::assert_eq(expected.clone(), actual);
216+
snapbox::assert_data_eq!(actual, expected.clone().raw());
216217
}
217218
}
218219
}

crates/mdman/tests/compare.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn run(name: &str) {
2222
name,
2323
format.extension(section)
2424
));
25-
snapbox::assert_eq(snapbox::Data::read_from(&expected_path, None), result);
25+
snapbox::assert_data_eq!(result, snapbox::Data::read_from(&expected_path, None).raw());
2626
}
2727
}
2828

crates/mdman/tests/invalid.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
use std::path::PathBuf;
44

55
use mdman::{Format, ManMap};
6+
use snapbox::prelude::*;
67

7-
fn run(name: &str, expected_error: &str) {
8+
fn run(name: &str, expected_error: impl IntoData) {
89
let input = PathBuf::from(format!("tests/invalid/{}", name));
910
match mdman::convert(&input, Format::Man, None, ManMap::new()) {
1011
Ok(_) => {
1112
panic!("expected {} to fail", name);
1213
}
1314
Err(e) => {
14-
snapbox::assert_eq(expected_error, e.to_string());
15+
snapbox::assert_data_eq!(e.to_string(), expected_error.raw());
1516
}
1617
}
1718
}

credential/cargo-credential/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cargo-credential"
3-
version = "0.4.5"
3+
version = "0.4.6"
44
rust-version.workspace = true
55
edition.workspace = true
66
license.workspace = true

credential/cargo-credential/src/stdio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ mod test {
143143

144144
#[test]
145145
fn stdin() {
146-
let tempdir = snapbox::path::PathFixture::mutable_temp().unwrap();
146+
let tempdir = snapbox::dir::DirRoot::mutable_temp().unwrap();
147147
let file = tempdir.path().unwrap().join("stdin");
148148
let mut file = OpenOptions::new()
149149
.read(true)

0 commit comments

Comments
 (0)