Skip to content

Commit

Permalink
Auto merge of #13963 - epage:snapbox, r=weihanglo
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed May 28, 2024
2 parents 95eeafa + 9af864e commit 11d0002
Show file tree
Hide file tree
Showing 284 changed files with 606 additions and 601 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ sha1 = "0.10.6"
sha2 = "0.10.8"
shell-escape = "0.1.5"
supports-hyperlinks = "3.0.0"
snapbox = { version = "0.5.9", features = ["diff", "path", "term-svg"] }
snapbox = { version = "0.6.5", features = ["diff", "dir", "term-svg"] }
tar = { version = "0.4.40", default-features = false }
tempfile = "3.10.1"
thiserror = "1.0.59"
Expand Down
20 changes: 7 additions & 13 deletions crates/cargo-test-support/src/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,15 @@ pub fn assert_ui() -> snapbox::Assert {
// Use `from_file_path` instead of `from_dir_path` so the trailing slash is
// put in the users output, rather than hidden in the variable
let root_url = url::Url::from_file_path(&root).unwrap().to_string();
let root = root.display().to_string();

let mut subs = snapbox::Substitutions::new();
subs.extend([
(
"[EXE]",
std::borrow::Cow::Borrowed(std::env::consts::EXE_SUFFIX),
),
("[ROOT]", std::borrow::Cow::Owned(root)),
("[ROOTURL]", std::borrow::Cow::Owned(root_url)),
])
.unwrap();
let mut subs = snapbox::Redactions::new();
subs.extend([("[EXE]", std::env::consts::EXE_SUFFIX)])
.unwrap();
subs.insert("[ROOT]", root).unwrap();
subs.insert("[ROOTURL]", root_url).unwrap();
snapbox::Assert::new()
.action_env(snapbox::DEFAULT_ACTION_ENV)
.substitutions(subs)
.action_env(snapbox::assert::DEFAULT_ACTION_ENV)
.redact_with(subs)
}

/// Normalizes the output so that it can be compared against the expected value.
Expand Down
4 changes: 2 additions & 2 deletions crates/cargo-test-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ macro_rules! t {
}

pub use snapbox::file;
pub use snapbox::path::current_dir;
pub use snapbox::str;
pub use snapbox::utils::current_dir;

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

Expand Down
5 changes: 3 additions & 2 deletions crates/cargo-util-schemas/src/core/partial_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ enum ErrorKind {
#[cfg(test)]
mod test {
use super::*;
use snapbox::prelude::*;
use snapbox::str;

#[test]
Expand All @@ -202,7 +203,7 @@ mod test {
Ok(result) => result.to_string(),
Err(err) => format!("didn't pass: {err}"),
};
snapbox::assert_eq(expected.clone(), actual);
snapbox::assert_data_eq!(actual, expected.clone().raw());
}
}

Expand Down Expand Up @@ -241,7 +242,7 @@ mod test {
Ok(result) => format!("didn't fail: {result:?}"),
Err(err) => err.to_string(),
};
snapbox::assert_eq(expected.clone(), actual);
snapbox::assert_data_eq!(actual, expected.clone().raw());
}
}
}
3 changes: 2 additions & 1 deletion crates/cargo-util-schemas/src/manifest/rust_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ enum RustVersionErrorKind {
#[cfg(test)]
mod test {
use super::*;
use snapbox::prelude::*;
use snapbox::str;

#[test]
Expand Down Expand Up @@ -212,7 +213,7 @@ mod test {
Ok(result) => format!("didn't fail: {result:?}"),
Err(err) => err.to_string(),
};
snapbox::assert_eq(expected.clone(), actual);
snapbox::assert_data_eq!(actual, expected.clone().raw());
}
}
}
2 changes: 1 addition & 1 deletion crates/mdman/tests/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn run(name: &str) {
name,
format.extension(section)
));
snapbox::assert_eq(snapbox::Data::read_from(&expected_path, None), result);
snapbox::assert_data_eq!(result, snapbox::Data::read_from(&expected_path, None).raw());
}
}

Expand Down
5 changes: 3 additions & 2 deletions crates/mdman/tests/invalid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
use std::path::PathBuf;

use mdman::{Format, ManMap};
use snapbox::prelude::*;

fn run(name: &str, expected_error: &str) {
fn run(name: &str, expected_error: impl IntoData) {
let input = PathBuf::from(format!("tests/invalid/{}", name));
match mdman::convert(&input, Format::Man, None, ManMap::new()) {
Ok(_) => {
panic!("expected {} to fail", name);
}
Err(e) => {
snapbox::assert_eq(expected_error, e.to_string());
snapbox::assert_data_eq!(e.to_string(), expected_error.raw());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion credential/cargo-credential/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cargo-credential"
version = "0.4.5"
version = "0.4.6"
rust-version.workspace = true
edition.workspace = true
license.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion credential/cargo-credential/src/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ mod test {

#[test]
fn stdin() {
let tempdir = snapbox::path::PathFixture::mutable_temp().unwrap();
let tempdir = snapbox::dir::DirRoot::mutable_temp().unwrap();
let file = tempdir.path().unwrap().join("stdin");
let mut file = OpenOptions::new()
.read(true)
Expand Down
9 changes: 5 additions & 4 deletions credential/cargo-credential/tests/examples.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::path::Path;

use snapbox::cmd::Command;
use snapbox::prelude::*;

#[test]
fn stdout_redirected() {
Expand All @@ -14,8 +15,8 @@ fn stdout_redirected() {
.stdin(format!("{get_request}\n"))
.arg("--cargo-plugin")
.assert()
.stdout_eq(format!("{hello}\n{err_not_supported}\n"))
.stderr_eq("message on stderr should be sent to the parent process\n")
.stdout_eq(format!("{hello}\n{err_not_supported}\n").raw())
.stderr_eq("message on stderr should be sent to the parent process\n".raw())
.success();
}

Expand All @@ -38,8 +39,8 @@ fn file_provider() {
.stdin(format!("{login_request}\n{get_request}\n"))
.arg("--cargo-plugin")
.assert()
.stdout_eq(format!("{hello}\n{login_response}\n{get_response}\n"))
.stderr_eq("")
.stdout_eq(format!("{hello}\n{login_response}\n{get_response}\n").raw())
.stderr_eq("".raw())
.success();
std::fs::remove_dir_all(&dir).unwrap();
}
7 changes: 3 additions & 4 deletions src/cargo/core/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -733,10 +733,9 @@ macro_rules! unstable_cli_options {
);
let mut expected = vec![$(stringify!($element)),*];
expected[2..].sort();
snapbox::assert_eq(
format!("{:#?}", expected),
format!("{:#?}", vec![$(stringify!($element)),*])
);
let expected = format!("{:#?}", expected);
let actual = format!("{:#?}", vec![$(stringify!($element)),*]);
snapbox::assert_data_eq!(actual, expected);
}
}
}
Expand Down
52 changes: 30 additions & 22 deletions src/cargo/util/toml/embedded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ fn split_source(input: &str) -> CargoResult<Source<'_>> {

#[cfg(test)]
mod test_expand {
use snapbox::str;

use super::*;

macro_rules! si {
Expand All @@ -276,8 +278,10 @@ mod test_expand {

#[test]
fn test_default() {
snapbox::assert_eq(
r#"[[bin]]
snapbox::assert_data_eq!(
si!(r#"fn main() {}"#),
str![[r#"
[[bin]]
name = "test-"
path = "/home/me/test.rs"
Expand All @@ -294,15 +298,22 @@ name = "test-"
strip = true
[workspace]
"#,
si!(r#"fn main() {}"#),
"#]]
);
}

#[test]
fn test_dependencies() {
snapbox::assert_matches(
r#"[[bin]]
snapbox::assert_data_eq!(
si!(r#"---cargo
[dependencies]
time="0.1.25"
---
fn main() {}
"#),
str![[r#"
[[bin]]
name = "test-"
path = [..]
Expand All @@ -322,20 +333,22 @@ name = "test-"
strip = true
[workspace]
"#,
si!(r#"---cargo
[dependencies]
time="0.1.25"
---
fn main() {}
"#),
"#]]
);
}

#[test]
fn test_no_infostring() {
snapbox::assert_matches(
r#"[[bin]]
snapbox::assert_data_eq!(
si!(r#"---
[dependencies]
time="0.1.25"
---
fn main() {}
"#),
str![[r#"
[[bin]]
name = "test-"
path = [..]
Expand All @@ -355,13 +368,8 @@ name = "test-"
strip = true
[workspace]
"#,
si!(r#"---
[dependencies]
time="0.1.25"
---
fn main() {}
"#),
"#]]
);
}
}
4 changes: 2 additions & 2 deletions tests/testsuite/cargo/help/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ fn case() {
.arg("--help")
.assert()
.success()
.stdout_matches(file!["stdout.term.svg"])
.stderr_matches(str![""]);
.stdout_eq(file!["stdout.term.svg"])
.stderr_eq(str![""]);
}
4 changes: 2 additions & 2 deletions tests/testsuite/cargo/z_help/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ fn case() {
.args(["-Z", "help"])
.assert()
.success()
.stdout_matches(file!["stdout.term.svg"])
.stderr_matches(str![""]);
.stdout_eq(file!["stdout.term.svg"])
.stderr_eq(str![""]);
}
4 changes: 2 additions & 2 deletions tests/testsuite/cargo_add/add_basic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ fn case() {
.current_dir(cwd)
.assert()
.success()
.stdout_matches(str![""])
.stderr_matches(file!["stderr.term.svg"]);
.stdout_eq(str![""])
.stderr_eq(file!["stderr.term.svg"]);

assert_ui().subset_matches(current_dir!().join("out"), &project_root);
}
4 changes: 2 additions & 2 deletions tests/testsuite/cargo_add/add_multiple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ fn case() {
.current_dir(cwd)
.assert()
.success()
.stdout_matches(str![""])
.stderr_matches(file!["stderr.term.svg"]);
.stdout_eq(str![""])
.stderr_eq(file!["stderr.term.svg"]);

assert_ui().subset_matches(current_dir!().join("out"), &project_root);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ fn case() {
.current_dir(cwd)
.assert()
.success()
.stdout_matches(str![""])
.stderr_matches(file!["stderr.term.svg"]);
.stdout_eq(str![""])
.stderr_eq(file!["stderr.term.svg"]);

assert_ui().subset_matches(current_dir!().join("out"), &project_root);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ fn case() {
.current_dir(cwd)
.assert()
.failure()
.stdout_matches(str![""])
.stderr_matches(file!["stderr.term.svg"]);
.stdout_eq(str![""])
.stderr_eq(file!["stderr.term.svg"]);

assert_ui().subset_matches(current_dir!().join("out"), &project_root);
}
4 changes: 2 additions & 2 deletions tests/testsuite/cargo_add/add_normalized_name_external/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ fn case() {
.current_dir(cwd)
.assert()
.success()
.stdout_matches(str![""])
.stderr_matches(file!["stderr.term.svg"]);
.stdout_eq(str![""])
.stderr_eq(file!["stderr.term.svg"]);

assert_ui().subset_matches(current_dir!().join("out"), &project_root);
}
Loading

0 comments on commit 11d0002

Please sign in to comment.