Skip to content

Commit

Permalink
refactor: Port from matches_contains to assert_e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed May 28, 2024
1 parent 18b4812 commit 2fa20f6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 46 deletions.
2 changes: 1 addition & 1 deletion crates/cargo-test-support/src/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
28 changes: 12 additions & 16 deletions tests/testsuite/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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::<ProcessError>().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 `<eof>`
--> [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;
Expand Down
16 changes: 5 additions & 11 deletions tests/testsuite/profile_trim_paths.rs
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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![]);
}
28 changes: 10 additions & 18 deletions tests/testsuite/registry_auth.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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| {
Expand Down

0 comments on commit 2fa20f6

Please sign in to comment.