Skip to content

Commit 995746b

Browse files
committed
refactor: Port from matches_contains to assert_e2e
1 parent eee1053 commit 995746b

File tree

4 files changed

+37
-45
lines changed

4 files changed

+37
-45
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ pub(crate) fn match_unordered(expected: &str, actual: &str, cwd: Option<&Path>)
405405
/// somewhere.
406406
///
407407
/// See [Patterns](index.html#patterns) for more information on pattern matching.
408-
pub fn match_contains(expected: &str, actual: &str, cwd: Option<&Path>) -> Result<()> {
408+
pub(crate) fn match_contains(expected: &str, actual: &str, cwd: Option<&Path>) -> Result<()> {
409409
let expected = normalize_expected(expected, cwd);
410410
let actual = normalize_actual(actual, cwd);
411411
let e: Vec<_> = expected.lines().map(|line| WildStr::new(line)).collect();

tests/testsuite/install.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use std::io::prelude::*;
55
use std::path::Path;
66
use std::thread;
77

8-
use cargo_test_support::compare;
98
use cargo_test_support::compare::assert_e2e;
109
use cargo_test_support::cross_compile;
1110
use cargo_test_support::git;
@@ -2298,26 +2297,23 @@ fn failed_install_retains_temp_directory() {
22982297
let err = cargo_process("install foo").exec_with_output().unwrap_err();
22992298
let err = err.downcast::<ProcessError>().unwrap();
23002299
let stderr = String::from_utf8(err.stderr.unwrap()).unwrap();
2301-
compare::match_contains(
2302-
"\
2300+
assert_e2e().eq(&stderr, str![[r#"
23032301
[UPDATING] `dummy-registry` index
23042302
[DOWNLOADING] crates ...
23052303
[DOWNLOADED] foo v0.0.1 (registry `dummy-registry`)
23062304
[INSTALLING] foo v0.0.1
23072305
[COMPILING] foo v0.0.1
2308-
",
2309-
&stderr,
2310-
None,
2311-
)
2312-
.unwrap();
2313-
compare::match_contains(
2314-
"error: failed to compile `foo v0.0.1`, intermediate artifacts can be found at \
2315-
`[..]`.\nTo reuse those artifacts with a future compilation, set the environment \
2316-
variable `CARGO_TARGET_DIR` to that path.",
2317-
&stderr,
2318-
None,
2319-
)
2320-
.unwrap();
2306+
[ERROR] expected one of `!` or `::`, found `<eof>`
2307+
--> [ROOT]/home/.cargo/registry/src/-[..]/foo-0.0.1/src/main.rs:1:1
2308+
|
2309+
1 | x
2310+
| ^ expected one of `!` or `::`
2311+
2312+
[ERROR] could not compile `foo` (bin "foo") due to 1 previous error
2313+
[ERROR] failed to compile `foo v0.0.1`, intermediate artifacts can be found at `[..]`.
2314+
To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path.
2315+
2316+
"#]]);
23212317

23222318
// Find the path in the output.
23232319
let stderr = stderr.split_once("found at `").unwrap().1;

tests/testsuite/profile_trim_paths.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
//! Tests for `-Ztrim-paths`.
22
33
use cargo_test_support::basic_manifest;
4+
use cargo_test_support::compare::assert_e2e;
45
use cargo_test_support::git;
56
use cargo_test_support::paths;
67
use cargo_test_support::project;
78
use cargo_test_support::registry::Package;
9+
use cargo_test_support::str;
810

911
#[cargo_test]
1012
fn gated_manifest() {
@@ -711,7 +713,6 @@ fn custom_build_env_var_trim_paths() {
711713
#[cfg(unix)]
712714
#[cargo_test(requires_lldb, nightly, reason = "-Zremap-path-scope is unstable")]
713715
fn lldb_works_after_trimmed() {
714-
use cargo_test_support::compare::match_contains;
715716
use cargo_util::is_ci;
716717

717718
if !is_ci() {
@@ -770,14 +771,17 @@ fn lldb_works_after_trimmed() {
770771
let bin_path = p.bin("foo");
771772
assert!(bin_path.is_file());
772773
let stdout = String::from_utf8(run_lldb(bin_path).stdout).unwrap();
773-
match_contains("[..]stopped[..]", &stdout, None).unwrap();
774-
match_contains("[..]stop reason = breakpoint[..]", &stdout, None).unwrap();
775-
match_contains(
776-
"\
777-
(lldb) continue
778-
Hello, Ferris!",
774+
assert_e2e().eq(
779775
&stdout,
780-
None,
781-
)
782-
.unwrap();
776+
str![[r#"
777+
...
778+
[..]stopped[..]
779+
[..]stop reason = breakpoint 1.1[..]
780+
...
781+
(lldb) continue
782+
Hello, Ferris!
783+
...
784+
785+
"#]],
786+
);
783787
}

tests/testsuite/registry_auth.rs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
//! Tests for registry authentication.
22
3-
use cargo_test_support::compare::match_contains;
3+
use cargo_test_support::compare::assert_e2e;
44
use cargo_test_support::registry::{Package, RegistryBuilder, Token};
5+
use cargo_test_support::str;
56
use cargo_test_support::{project, Execs, Project};
67

78
fn cargo(p: &Project, s: &str) -> Execs {
@@ -473,23 +474,14 @@ fn token_not_logged() {
473474
.exec_with_output()
474475
.unwrap();
475476
let log = String::from_utf8(output.stderr).unwrap();
476-
let lines = "\
477-
[UPDATING] crates.io index
478-
[PACKAGING] foo v0.1.0 [..]
479-
[VERIFYING] foo v0.1.0 [..]
480-
[DOWNLOADING] crates ...
481-
[DOWNLOADED] bar v1.0.0
482-
[COMPILING] bar v1.0.0
483-
[COMPILING] foo v0.1.0 [..]
484-
[FINISHED] [..]
485-
[PACKAGED] 3 files[..]
486-
[UPLOADING] foo v0.1.0[..]
487-
[UPLOADED] foo v0.1.0 to registry `crates-io`
488-
[NOTE] waiting [..]
489-
";
490-
for line in lines.lines() {
491-
match_contains(line, &log, None).unwrap();
492-
}
477+
assert_e2e().eq(
478+
&log,
479+
str![[r#"
480+
...
481+
[PUBLISHED] foo v0.1.0 at registry `crates-io`
482+
483+
"#]],
484+
);
493485
let authorizations: Vec<_> = log
494486
.lines()
495487
.filter(|line| {

0 commit comments

Comments
 (0)