Skip to content

Commit

Permalink
refactor: Port from matches_unordered to assert_e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed May 29, 2024
1 parent 3054936 commit eee1053
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
8 changes: 6 additions & 2 deletions crates/cargo-test-support/src/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ pub fn assert_e2e() -> snapbox::Assert {
.redact_with(subs)
}

static MIN_LITERAL_REDACTIONS: &[(&str, &str)] = &[("[EXE]", std::env::consts::EXE_SUFFIX)];
static MIN_LITERAL_REDACTIONS: &[(&str, &str)] = &[
("[EXE]", std::env::consts::EXE_SUFFIX),
("[BROKEN_PIPE]", "Broken pipe (os error 32)"),
("[BROKEN_PIPE]", "The pipe is being closed. (os error 232)"),
];
static E2E_LITERAL_REDACTIONS: &[(&str, &str)] = &[
("[RUNNING]", " Running"),
("[COMPILING]", " Compiling"),
Expand Down Expand Up @@ -351,7 +355,7 @@ pub(crate) fn assert_match_exact(expected: &str, actual: &str) {
/// of the lines.
///
/// See [Patterns](index.html#patterns) for more information on pattern matching.
pub fn match_unordered(expected: &str, actual: &str, cwd: Option<&Path>) -> Result<()> {
pub(crate) fn match_unordered(expected: &str, actual: &str, cwd: Option<&Path>) -> Result<()> {
let expected = normalize_expected(expected, cwd);
let actual = normalize_actual(actual, cwd);
let e: Vec<_> = expected.lines().map(|line| WildStr::new(line)).collect();
Expand Down
23 changes: 13 additions & 10 deletions tests/testsuite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ use cargo::{
ops::CompileOptions,
GlobalContext,
};
use cargo_test_support::compare::assert_e2e;
use cargo_test_support::paths::{root, CargoPathExt};
use cargo_test_support::prelude::*;
use cargo_test_support::registry::Package;
use cargo_test_support::str;
use cargo_test_support::{
basic_bin_manifest, basic_lib_manifest, basic_manifest, cargo_exe, cargo_process, compare, git,
basic_bin_manifest, basic_lib_manifest, basic_manifest, cargo_exe, cargo_process, git,
is_nightly, main_file, paths, process, project, rustc_host, sleep_ms, symlink_supported, t,
tools, Execs, ProjectBuilder,
};
Expand Down Expand Up @@ -6448,17 +6451,17 @@ fn close_output() {
};

let stderr = spawn(false);
compare::match_unordered(
"\
[COMPILING] foo [..]
assert_e2e().eq(
&stderr,
str![[r#"
[COMPILING] foo v0.1.0 ([ROOT]/foo)
hello stderr!
[ERROR] [..]
[ERROR] [BROKEN_PIPE]
[WARNING] build failed, waiting for other jobs to finish...
",
&stderr,
None,
)
.unwrap();
"#]]
.unordered(),
);

// Try again with stderr.
p.build_dir().rm_rf();
Expand Down

0 comments on commit eee1053

Please sign in to comment.