From 2fa20f6b59a1b419f7a261ae6807470d167f5445 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Sat, 25 May 2024 12:24:28 -0500 Subject: [PATCH] refactor: Port from matches_contains to assert_e2e --- crates/cargo-test-support/src/compare.rs | 2 +- tests/testsuite/install.rs | 28 ++++++++++-------------- tests/testsuite/profile_trim_paths.rs | 16 +++++--------- tests/testsuite/registry_auth.rs | 28 +++++++++--------------- 4 files changed, 28 insertions(+), 46 deletions(-) diff --git a/crates/cargo-test-support/src/compare.rs b/crates/cargo-test-support/src/compare.rs index 0579399a8631..822d516a7584 100644 --- a/crates/cargo-test-support/src/compare.rs +++ b/crates/cargo-test-support/src/compare.rs @@ -401,7 +401,7 @@ pub(crate) fn match_unordered(expected: &str, actual: &str, cwd: Option<&Path>) /// somewhere. /// /// See [Patterns](index.html#patterns) for more information on pattern matching. -pub fn match_contains(expected: &str, actual: &str, cwd: Option<&Path>) -> Result<()> { +pub(crate) fn match_contains(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(); diff --git a/tests/testsuite/install.rs b/tests/testsuite/install.rs index a0033d98a61d..d878cbf86381 100644 --- a/tests/testsuite/install.rs +++ b/tests/testsuite/install.rs @@ -5,7 +5,6 @@ use std::io::prelude::*; use std::path::Path; use std::thread; -use cargo_test_support::compare; use cargo_test_support::compare::assert_e2e; use cargo_test_support::cross_compile; use cargo_test_support::git; @@ -2298,26 +2297,23 @@ fn failed_install_retains_temp_directory() { let err = cargo_process("install foo").exec_with_output().unwrap_err(); let err = err.downcast::().unwrap(); let stderr = String::from_utf8(err.stderr.unwrap()).unwrap(); - compare::match_contains( - "\ + assert_e2e().eq(&stderr, str![[r#" [UPDATING] `dummy-registry` index [DOWNLOADING] crates ... [DOWNLOADED] foo v0.0.1 (registry `dummy-registry`) [INSTALLING] foo v0.0.1 [COMPILING] foo v0.0.1 -", - &stderr, - None, - ) - .unwrap(); - compare::match_contains( - "error: failed to compile `foo v0.0.1`, intermediate artifacts can be found at \ - `[..]`.\nTo reuse those artifacts with a future compilation, set the environment \ - variable `CARGO_TARGET_DIR` to that path.", - &stderr, - None, - ) - .unwrap(); +[ERROR] expected one of `!` or `::`, found `` + --> [ROOT]/home/.cargo/registry/src/-[..]/foo-0.0.1/src/main.rs:1:1 + | +1 | x + | ^ expected one of `!` or `::` + +[ERROR] could not compile `foo` (bin "foo") due to 1 previous error +[ERROR] failed to compile `foo v0.0.1`, intermediate artifacts can be found at `[..]`. +To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path. + +"#]]); // Find the path in the output. let stderr = stderr.split_once("found at `").unwrap().1; diff --git a/tests/testsuite/profile_trim_paths.rs b/tests/testsuite/profile_trim_paths.rs index fbdec2a69196..b8bd00ce82bf 100644 --- a/tests/testsuite/profile_trim_paths.rs +++ b/tests/testsuite/profile_trim_paths.rs @@ -1,10 +1,12 @@ //! Tests for `-Ztrim-paths`. use cargo_test_support::basic_manifest; +use cargo_test_support::compare::assert_e2e; use cargo_test_support::git; use cargo_test_support::paths; use cargo_test_support::project; use cargo_test_support::registry::Package; +use cargo_test_support::str; #[cargo_test] fn gated_manifest() { @@ -711,7 +713,6 @@ fn custom_build_env_var_trim_paths() { #[cfg(unix)] #[cargo_test(requires_lldb, nightly, reason = "-Zremap-path-scope is unstable")] fn lldb_works_after_trimmed() { - use cargo_test_support::compare::match_contains; use cargo_util::is_ci; if !is_ci() { @@ -770,14 +771,7 @@ fn lldb_works_after_trimmed() { let bin_path = p.bin("foo"); assert!(bin_path.is_file()); let stdout = String::from_utf8(run_lldb(bin_path).stdout).unwrap(); - match_contains("[..]stopped[..]", &stdout, None).unwrap(); - match_contains("[..]stop reason = breakpoint[..]", &stdout, None).unwrap(); - match_contains( - "\ -(lldb) continue -Hello, Ferris!", - &stdout, - None, - ) - .unwrap(); + assert_e2e().eq(&stdout, str![]); + assert_e2e().eq(&stdout, str![]); + assert_e2e().eq(&stdout, str![]); } diff --git a/tests/testsuite/registry_auth.rs b/tests/testsuite/registry_auth.rs index 1ac1ba284445..12c009981348 100644 --- a/tests/testsuite/registry_auth.rs +++ b/tests/testsuite/registry_auth.rs @@ -1,7 +1,8 @@ //! Tests for registry authentication. -use cargo_test_support::compare::match_contains; +use cargo_test_support::compare::assert_e2e; use cargo_test_support::registry::{Package, RegistryBuilder, Token}; +use cargo_test_support::str; use cargo_test_support::{project, Execs, Project}; fn cargo(p: &Project, s: &str) -> Execs { @@ -473,23 +474,14 @@ fn token_not_logged() { .exec_with_output() .unwrap(); let log = String::from_utf8(output.stderr).unwrap(); - let lines = "\ -[UPDATING] crates.io index -[PACKAGING] foo v0.1.0 [..] -[VERIFYING] foo v0.1.0 [..] -[DOWNLOADING] crates ... -[DOWNLOADED] bar v1.0.0 -[COMPILING] bar v1.0.0 -[COMPILING] foo v0.1.0 [..] -[FINISHED] [..] -[PACKAGED] 3 files[..] -[UPLOADING] foo v0.1.0[..] -[UPLOADED] foo v0.1.0 to registry `crates-io` -[NOTE] waiting [..] -"; - for line in lines.lines() { - match_contains(line, &log, None).unwrap(); - } + assert_e2e().eq( + &log, + str![[r#" +... +[PUBLISHED] foo v0.1.0 at registry `crates-io` + +"#]], + ); let authorizations: Vec<_> = log .lines() .filter(|line| {