From e41c718229426577929078d343e8f7c1026b2bc7 Mon Sep 17 00:00:00 2001 From: heisen-li Date: Mon, 17 Jun 2024 19:31:44 +0800 Subject: [PATCH 1/7] test: migrate build_script_extra_link_arg to snapbox --- .../testsuite/build_script_extra_link_arg.rs | 123 +++++++++++------- 1 file changed, 73 insertions(+), 50 deletions(-) diff --git a/tests/testsuite/build_script_extra_link_arg.rs b/tests/testsuite/build_script_extra_link_arg.rs index 25132ef4db82..ca7b4863cd34 100644 --- a/tests/testsuite/build_script_extra_link_arg.rs +++ b/tests/testsuite/build_script_extra_link_arg.rs @@ -4,9 +4,8 @@ // because MSVC link.exe just gives a warning on unknown flags (how helpful!), // and other linkers will return an error. -#![allow(deprecated)] - use cargo_test_support::registry::Package; +use cargo_test_support::str; use cargo_test_support::{basic_bin_manifest, basic_lib_manifest, basic_manifest, project}; #[cargo_test] @@ -26,8 +25,11 @@ fn build_script_extra_link_arg_bin() { p.cargo("build -v") .without_status() - .with_stderr_contains( - "[RUNNING] `rustc --crate-name foo [..]-C link-arg=--this-is-a-bogus-flag[..]", + .with_stderr_data( + "\ +... +[RUNNING] `rustc --crate-name foo [..]-C link-arg=--this-is-a-bogus-flag[..] +...", ) .run(); } @@ -66,11 +68,17 @@ fn build_script_extra_link_arg_bin_single() { p.cargo("build -v") .without_status() - .with_stderr_contains( - "[RUNNING] `rustc --crate-name foo [..]-C link-arg=--bogus-flag-all -C link-arg=--bogus-flag-foo[..]", + .with_stderr_data( + "\ +... +[RUNNING] `rustc --crate-name foo [..]-C link-arg=--bogus-flag-all -C link-arg=--bogus-flag-foo[..] +...", ) - .with_stderr_contains( - "[RUNNING] `rustc --crate-name bar [..]-C link-arg=--bogus-flag-all -C link-arg=--bogus-flag-bar[..]", + .with_stderr_data( + "\ +... +[RUNNING] `rustc --crate-name bar [..]-C link-arg=--bogus-flag-all -C link-arg=--bogus-flag-bar[..] +...", ) .run(); } @@ -92,8 +100,11 @@ fn build_script_extra_link_arg() { p.cargo("build -v") .without_status() - .with_stderr_contains( - "[RUNNING] `rustc --crate-name foo [..]-C link-arg=--this-is-a-bogus-flag[..]", + .with_stderr_data( + "\ +... +[RUNNING] `rustc --crate-name foo [..]-C link-arg=--this-is-a-bogus-flag[..] +...", ) .run(); } @@ -127,11 +138,12 @@ fn link_arg_missing_target() { p.cargo("check") .with_status(101) - .with_stderr("\ -[COMPILING] foo [..] -error: invalid instruction `cargo::rustc-link-arg-bins` from build script of `foo v0.0.1 ([ROOT]/foo)` + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[ERROR] invalid instruction `cargo::rustc-link-arg-bins` from build script of `foo v0.0.1 ([ROOT]/foo)` The package foo v0.0.1 ([ROOT]/foo) does not have a bin target. -") + +"#]]) .run(); p.change_file( @@ -141,13 +153,12 @@ The package foo v0.0.1 ([ROOT]/foo) does not have a bin target. p.cargo("check") .with_status(101) - .with_stderr( - "\ -[COMPILING] foo [..] -error: invalid instruction `cargo::rustc-link-arg-bin` from build script of `foo v0.0.1 ([ROOT]/foo)` + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[ERROR] invalid instruction `cargo::rustc-link-arg-bin` from build script of `foo v0.0.1 ([ROOT]/foo)` The package foo v0.0.1 ([ROOT]/foo) does not have a bin target with the name `abc`. -", - ) + +"#]]) .run(); p.change_file( @@ -157,13 +168,12 @@ The package foo v0.0.1 ([ROOT]/foo) does not have a bin target with the name `ab p.cargo("check") .with_status(101) - .with_stderr( - "\ -[COMPILING] foo [..] -error: invalid instruction `cargo::rustc-link-arg-bin=abc` from build script of `foo v0.0.1 ([ROOT]/foo)` + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[ERROR] invalid instruction `cargo::rustc-link-arg-bin=abc` from build script of `foo v0.0.1 ([ROOT]/foo)` The instruction should have the form cargo::rustc-link-arg-bin=BIN=ARG -", - ) + +"#]]) .run(); } @@ -203,24 +213,26 @@ fn cdylib_link_arg_transitive() { .build(); p.cargo("build -v") .without_status() - .with_stderr_contains( + .with_stderr_data( "\ -[COMPILING] bar v1.0.0 [..] +... +[COMPILING] bar v1.0.0 ([ROOT]/foo/bar) [RUNNING] `rustc --crate-name build_script_build --edition=2015 bar/build.rs [..] -[RUNNING] `[..]build-script-build[..] -warning: bar@1.0.0: cargo::rustc-link-arg-cdylib was specified in the build script of bar v1.0.0 \ +[RUNNING] `[ROOT]/foo/target/debug/build/bar-[HASH]/build-script-build` +[WARNING] bar@1.0.0: cargo::rustc-link-arg-cdylib was specified in the build script of bar v1.0.0 \ ([ROOT]/foo/bar), but that package does not contain a cdylib target Allowing this was an unintended change in the 1.50 release, and may become an error in \ the future. For more information, see . [RUNNING] `rustc --crate-name bar --edition=2015 bar/src/lib.rs [..] -[COMPILING] foo v0.1.0 [..] +[COMPILING] foo v0.1.0 ([ROOT]/foo) [RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]-C link-arg=--bogus[..]` -", +...", ) .run(); } +#[allow(deprecated)] #[cargo_test] fn link_arg_transitive_not_allowed() { // Verify that transitive dependencies don't pass link args. @@ -260,21 +272,20 @@ fn link_arg_transitive_not_allowed() { .build(); p.cargo("build -v") - .with_stderr( - "\ -[UPDATING] [..] + .with_stderr_data(str![[r#" +[UPDATING] `dummy-registry` index [LOCKING] 2 packages to latest compatible versions -[DOWNLOADING] [..] -[DOWNLOADED] [..] +[DOWNLOADING] crates ... +[DOWNLOADED] bar v1.0.0 (registry `dummy-registry`) [COMPILING] bar v1.0.0 [RUNNING] `rustc --crate-name build_script_build [..] -[RUNNING] `[..]/build-script-build[..] +[RUNNING] `[ROOT]/foo/target/debug/build/bar-[HASH]/build-script-build` [RUNNING] `rustc --crate-name bar [..] -[COMPILING] foo v0.1.0 [..] +[COMPILING] foo v0.1.0 ([ROOT]/foo) [RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..] -[FINISHED] `dev` profile [..] -", - ) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .with_stderr_does_not_contain("--bogus") .run(); } @@ -303,8 +314,11 @@ fn link_arg_with_doctest() { p.cargo("test --doc -v") .without_status() - .with_stderr_contains( - "[RUNNING] `rustdoc [..]--crate-name foo [..]-C link-arg=--this-is-a-bogus-flag[..]", + .with_stderr_data( + "\ +... +[RUNNING] `rustdoc [..]--crate-name foo [..]-C link-arg=--this-is-a-bogus-flag[..] +...", ) .run(); } @@ -327,8 +341,11 @@ fn build_script_extra_link_arg_tests() { p.cargo("test -v") .without_status() - .with_stderr_contains( - "[RUNNING] `rustc --crate-name test_foo [..]-C link-arg=--this-is-a-bogus-flag[..]", + .with_stderr_data( + "\ +... +[RUNNING] `rustc --crate-name test_foo [..]-C link-arg=--this-is-a-bogus-flag[..] +...", ) .run(); } @@ -351,8 +368,11 @@ fn build_script_extra_link_arg_benches() { p.cargo("bench -v") .without_status() - .with_stderr_contains( - "[RUNNING] `rustc --crate-name bench_foo [..]-C link-arg=--this-is-a-bogus-flag[..]", + .with_stderr_data( + "\ +... +[RUNNING] `rustc --crate-name bench_foo [..]-C link-arg=--this-is-a-bogus-flag[..] +...", ) .run(); } @@ -375,8 +395,11 @@ fn build_script_extra_link_arg_examples() { p.cargo("build -v --examples") .without_status() - .with_stderr_contains( - "[RUNNING] `rustc --crate-name example_foo [..]-C link-arg=--this-is-a-bogus-flag[..]", + .with_stderr_data( + "\ +... +[RUNNING] `rustc --crate-name example_foo [..]-C link-arg=--this-is-a-bogus-flag[..] +...", ) .run(); } From 413844bc131db0d953ebc90499ad1be3373f8668 Mon Sep 17 00:00:00 2001 From: heisen-li Date: Tue, 18 Jun 2024 18:59:06 +0800 Subject: [PATCH 2/7] test: migrate cache_message to snapbox --- tests/testsuite/cache_messages.rs | 174 +++++++++++++++++++----------- 1 file changed, 114 insertions(+), 60 deletions(-) diff --git a/tests/testsuite/cache_messages.rs b/tests/testsuite/cache_messages.rs index 51ca2a30defb..6a14f9c74f65 100644 --- a/tests/testsuite/cache_messages.rs +++ b/tests/testsuite/cache_messages.rs @@ -1,8 +1,7 @@ //! Tests for caching compiler diagnostics. -#![allow(deprecated)] - use super::messages::raw_rustc_output; +use cargo_test_support::str; use cargo_test_support::tools; use cargo_test_support::{basic_manifest, is_coarse_mtime, project, registry::Package, sleep_ms}; @@ -160,7 +159,16 @@ fn clears_cache_after_fix() { // Make sure the cache is invalidated when there is no output. let p = project().file("src/lib.rs", "fn asdf() {}").build(); // Fill the cache. - p.cargo("check").with_stderr_contains("[..]asdf[..]").run(); + p.cargo("check") + .with_stderr_data(str![[r#" +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[WARNING] function `asdf` is never used +... +[WARNING] `foo` (lib) generated 1 warning +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) + .run(); let cpath = p .glob("target/debug/.fingerprint/foo-*/output-*") .next() @@ -175,13 +183,12 @@ fn clears_cache_after_fix() { p.change_file("src/lib.rs", ""); p.cargo("check") - .with_stdout("") - .with_stderr( - "\ -[CHECKING] foo [..] -[FINISHED] [..] -", - ) + .with_stdout_data("") + .with_stderr_data(str![[r#" +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); assert_eq!( p.glob("target/debug/.fingerprint/foo-*/output-*").count(), @@ -190,12 +197,11 @@ fn clears_cache_after_fix() { // And again, check the cache is correct. p.cargo("check") - .with_stdout("") - .with_stderr( - "\ -[FINISHED] [..] -", - ) + .with_stdout_data("") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -267,13 +273,39 @@ fn very_verbose() { .build(); p.cargo("check -vv") - .with_stderr_contains("[..]not_used[..]") + .with_stderr_data(str![[r#" +[UPDATING] `dummy-registry` index +[LOCKING] 2 packages to latest compatible versions +[DOWNLOADING] crates ... +[DOWNLOADED] bar v1.0.0 (registry `dummy-registry`) +[CHECKING] bar v1.0.0 +[RUNNING] [..] +[WARNING] function `not_used` is never used +... +[CHECKING] foo v0.1.0 ([ROOT]/foo) +[RUNNING] [..] +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); - p.cargo("check").with_stderr("[FINISHED] [..]").run(); + p.cargo("check") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) + .run(); p.cargo("check -vv") - .with_stderr_contains("[..]not_used[..]") + .with_stderr_data(str![[r#" +[FRESH] bar v1.0.0 +[WARNING] function `not_used` is never used +... +[WARNING] `bar` (lib) generated 1 warning +[FRESH] foo v0.1.0 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -346,25 +378,23 @@ fn replay_non_json() { let p = project().file("src/lib.rs", "").build(); p.cargo("check") .env("RUSTC", rustc.bin("rustc_alt")) - .with_stderr( - "\ -[CHECKING] foo [..] + .with_stderr_data(str![[r#" +[CHECKING] foo v0.0.1 ([ROOT]/foo) line 1 line 2 -[FINISHED] `dev` profile [..] -", - ) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); p.cargo("check") .env("RUSTC", rustc.bin("rustc_alt")) - .with_stderr( - "\ + .with_stderr_data(str![[r#" line 1 line 2 -[FINISHED] `dev` profile [..] -", - ) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -407,11 +437,11 @@ fn caching_large_output() { let p = project().file("src/lib.rs", "").build(); p.cargo("check") .env("RUSTC", rustc.bin("rustc_alt")) - .with_stderr(&format!( + .with_stderr_data(&format!( "\ -[CHECKING] foo [..] -{}warning: `foo` (lib) generated 250 warnings -[FINISHED] `dev` profile [..] +[CHECKING] foo v0.0.1 ([ROOT]/foo) +{}[WARNING] `foo` (lib) generated 250 warnings +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s ", expected )) @@ -419,10 +449,10 @@ fn caching_large_output() { p.cargo("check") .env("RUSTC", rustc.bin("rustc_alt")) - .with_stderr(&format!( + .with_stderr_data(&format!( "\ -{}warning: `foo` (lib) generated 250 warnings -[FINISHED] `dev` profile [..] +{}[WARNING] `foo` (lib) generated 250 warnings +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s ", expected )) @@ -441,44 +471,61 @@ fn rustc_workspace_wrapper() { p.cargo("check -v") .env("RUSTC_WORKSPACE_WRAPPER", tools::echo_wrapper()) - .with_stderr_contains( - "WRAPPER CALLED: rustc --crate-name foo --edition=2015 src/lib.rs [..]", - ) + .with_stderr_data(str![[r#" +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[RUNNING] [..]/rustc-echo-wrapper[EXE] rustc --crate-name foo [..] +WRAPPER CALLED: rustc --crate-name foo --edition=2015 src/lib.rs [..] +[WARNING] function `unused_func` is never used +... +[WARNING] `foo` (lib) generated 1 warning +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); // Check without a wrapper should rebuild p.cargo("check -v") - .with_stderr_contains( - "\ -[CHECKING] foo [..] -[RUNNING] `rustc[..] -[WARNING] [..]unused_func[..] -", - ) - .with_stdout_does_not_contain( - "WRAPPER CALLED: rustc --crate-name foo --edition=2015 src/lib.rs [..]", - ) + .with_stderr_data(str![[r#" +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[RUNNING] `rustc[..]` +[WARNING] function `unused_func` is never used +... +[WARNING] `foo` (lib) generated 1 warning +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) + .with_stdout_data("") .run(); // Again, reading from the cache. p.cargo("check -v") .env("RUSTC_WORKSPACE_WRAPPER", tools::echo_wrapper()) - .with_stderr_contains("[FRESH] foo [..]") - .with_stdout_does_not_contain( - "WRAPPER CALLED: rustc --crate-name foo --edition=2015 src/lib.rs [..]", - ) + .with_stderr_data(str![[r#" +[FRESH] foo v0.0.1 ([ROOT]/foo) +WRAPPER CALLED: rustc [..] +... +[WARNING] `foo` (lib) generated 1 warning +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) + .with_stdout_data("") .run(); // And `check` should also be fresh, reading from cache. p.cargo("check -v") - .with_stderr_contains("[FRESH] foo [..]") - .with_stderr_contains("[WARNING] [..]unused_func[..]") - .with_stdout_does_not_contain( - "WRAPPER CALLED: rustc --crate-name foo --edition=2015 src/lib.rs [..]", - ) + .with_stderr_data(str![[r#" +[FRESH] foo v0.0.1 ([ROOT]/foo) +[WARNING] function `unused_func` is never used +... +[WARNING] `foo` (lib) generated 1 warning +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) + .with_stdout_data("") .run(); } +#[allow(deprecated)] #[cargo_test] fn wacky_hashless_fingerprint() { // On Windows, executables don't have hashes. This checks for a bad @@ -491,7 +538,14 @@ fn wacky_hashless_fingerprint() { .with_stderr_does_not_contain("[..]unused[..]") .run(); p.cargo("check --bin a") - .with_stderr_contains("[..]unused[..]") + .with_stderr_data(str![[r#" +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[WARNING] unused variable: `unused` +... +[WARNING] `foo` (bin "a") generated 1 warning +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); // This should not pick up the cache from `a`. p.cargo("check --bin b") From 2e1f7b47c707f117aefb08f32ace5b8d1e4f52f6 Mon Sep 17 00:00:00 2001 From: heisen-li Date: Tue, 18 Jun 2024 18:59:47 +0800 Subject: [PATCH 3/7] test: migrate cache_lock to snapbox --- tests/testsuite/cache_lock.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/testsuite/cache_lock.rs b/tests/testsuite/cache_lock.rs index c6ed0874cb56..8304eaebe725 100644 --- a/tests/testsuite/cache_lock.rs +++ b/tests/testsuite/cache_lock.rs @@ -1,7 +1,5 @@ //! Tests for `CacheLock`. -#![allow(deprecated)] - use crate::config::GlobalContextBuilder; use cargo::util::cache_lock::{CacheLockMode, CacheLocker}; use cargo_test_support::paths::{self, CargoPathExt}; From 3bc397b197809eea6de32deea57ad84d28585e9f Mon Sep 17 00:00:00 2001 From: eth3lbert Date: Tue, 18 Jun 2024 15:46:53 +0800 Subject: [PATCH 4/7] test: migrate tree to snapbox --- tests/testsuite/tree.rs | 1045 ++++++++++++++++++--------------------- 1 file changed, 486 insertions(+), 559 deletions(-) diff --git a/tests/testsuite/tree.rs b/tests/testsuite/tree.rs index d96243006543..0fd30a55486e 100644 --- a/tests/testsuite/tree.rs +++ b/tests/testsuite/tree.rs @@ -1,10 +1,9 @@ //! Tests for the `cargo tree` command. -#![allow(deprecated)] - use super::features2::switch_to_resolver_2; use cargo_test_support::cross_compile::{self, alternate}; use cargo_test_support::registry::{Dependency, Package}; +use cargo_test_support::str; use cargo_test_support::{basic_manifest, git, project, rustc_host, Project}; fn make_simple_proj() -> Project { @@ -44,9 +43,8 @@ fn simple() { let p = make_simple_proj(); p.cargo("tree") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) ├── a v1.0.0 │ └── b v1.0.0 │ └── c v1.0.0 @@ -57,18 +55,17 @@ foo v0.1.0 ([..]/foo) [dev-dependencies] └── devdep v1.0.0 └── b v1.0.0 (*) -", - ) + +"#]]) .run(); p.cargo("tree -p bdep") - .with_stdout( - "\ + .with_stdout_data(str![[r#" bdep v1.0.0 └── b v1.0.0 └── c v1.0.0 -", - ) + +"#]]) .run(); } @@ -104,63 +101,63 @@ fn virtual_workspace() { .build(); p.cargo("tree") - .with_stdout( - "\ -a v1.0.0 ([..]/foo/a) + .with_stdout_data(str![[r#" +a v1.0.0 ([ROOT]/foo/a) -baz v0.1.0 ([..]/foo/baz) -├── c v1.0.0 ([..]/foo/c) +baz v0.1.0 ([ROOT]/foo/baz) +├── c v1.0.0 ([ROOT]/foo/c) └── somedep v1.0.0 -c v1.0.0 ([..]/foo/c) -", - ) +c v1.0.0 ([ROOT]/foo/c) + +"#]]) .run(); - p.cargo("tree -p a").with_stdout("a v1.0.0 [..]").run(); + p.cargo("tree -p a") + .with_stdout_data(str![[r#" +a v1.0.0 ([ROOT]/foo/a) + +"#]]) + .run(); p.cargo("tree") .cwd("baz") - .with_stdout( - "\ -baz v0.1.0 ([..]/foo/baz) -├── c v1.0.0 ([..]/foo/c) + .with_stdout_data(str![[r#" +baz v0.1.0 ([ROOT]/foo/baz) +├── c v1.0.0 ([ROOT]/foo/c) └── somedep v1.0.0 -", - ) + +"#]]) .run(); // exclude baz p.cargo("tree --workspace --exclude baz") - .with_stdout( - "\ -a v1.0.0 ([..]/foo/a) + .with_stdout_data(str![[r#" +a v1.0.0 ([ROOT]/foo/a) -c v1.0.0 ([..]/foo/c) -", - ) +c v1.0.0 ([ROOT]/foo/c) + +"#]]) .run(); // exclude glob '*z' p.cargo("tree --workspace --exclude '*z'") - .with_stdout( - "\ -a v1.0.0 ([..]/foo/a) + .with_stdout_data(str![[r#" +a v1.0.0 ([ROOT]/foo/a) -c v1.0.0 ([..]/foo/c) -", - ) +c v1.0.0 ([ROOT]/foo/c) + +"#]]) .run(); // include glob '*z' p.cargo("tree -p '*z'") - .with_stdout( - "\ -baz v0.1.0 ([..]/foo/baz) -├── c v1.0.0 ([..]/foo/c) + .with_stdout_data(str![[r#" +baz v0.1.0 ([ROOT]/foo/baz) +├── c v1.0.0 ([ROOT]/foo/c) └── somedep v1.0.0 -", - ) + +"#]]) .run(); } @@ -202,9 +199,8 @@ fn dedupe_edges() { .build(); p.cargo("tree") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) ├── a v1.0.0 │ └── manyfeat v1.0.0 │ └── bitflags v1.0.0 @@ -212,8 +208,8 @@ foo v0.1.0 ([..]/foo) │ └── manyfeat v1.0.0 (*) └── c v1.0.0 └── manyfeat v1.0.0 (*) -", - ) + +"#]]) .run(); } @@ -241,15 +237,14 @@ fn renamed_deps() { .build(); p.cargo("tree") - .with_stdout( - "\ -foo v1.0.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v1.0.0 ([ROOT]/foo) ├── bar v1.0.0 │ └── one v1.0.0 └── bar v2.0.0 └── two v1.0.0 -", - ) + +"#]]) .run(); } @@ -284,14 +279,13 @@ fn source_kinds() { .build(); p.cargo("tree") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) -├── gitdep v1.0.0 (file://[..]/gitdep#[..]) -├── pathdep v1.0.0 ([..]/foo/pathdep) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) +├── gitdep v1.0.0 ([ROOTURL]/gitdep#[..]) +├── pathdep v1.0.0 ([ROOT]/foo/pathdep) └── regdep v1.0.0 -", - ) + +"#]]) .run(); } @@ -320,40 +314,36 @@ fn features() { .build(); p.cargo("tree") - .with_stdout( - "\ -a v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +a v0.1.0 ([ROOT]/foo) └── optdep_default v1.0.0 -", - ) + +"#]]) .run(); p.cargo("tree --no-default-features") - .with_stdout( - "\ -a v0.1.0 ([..]/foo) -", - ) + .with_stdout_data(str![[r#" +a v0.1.0 ([ROOT]/foo) + +"#]]) .run(); p.cargo("tree --all-features") - .with_stdout( - "\ -a v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +a v0.1.0 ([ROOT]/foo) ├── optdep v1.0.0 └── optdep_default v1.0.0 -", - ) + +"#]]) .run(); p.cargo("tree --features optdep") - .with_stdout( - "\ -a v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +a v0.1.0 ([ROOT]/foo) ├── optdep v1.0.0 └── optdep_default v1.0.0 -", - ) + +"#]]) .run(); } @@ -411,23 +401,21 @@ fn filters_target() { .build(); p.cargo("tree") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) ├── hostdep v1.0.0 └── pm_host v1.0.0 (proc-macro) [build-dependencies] └── build_host_dep v1.0.0 └── hostdep v1.0.0 -", - ) + +"#]]) .run(); p.cargo("tree --target") .arg(alternate()) - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) ├── pm_target v1.0.0 (proc-macro) └── targetdep v1.0.0 [build-dependencies] @@ -435,28 +423,26 @@ foo v0.1.0 ([..]/foo) └── hostdep v1.0.0 [dev-dependencies] └── devdep v1.0.0 -", - ) + +"#]]) .run(); p.cargo("tree --target") .arg(rustc_host()) - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) ├── hostdep v1.0.0 └── pm_host v1.0.0 (proc-macro) [build-dependencies] └── build_host_dep v1.0.0 └── hostdep v1.0.0 -", - ) + +"#]]) .run(); p.cargo("tree --target=all") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) ├── hostdep v1.0.0 ├── pm_host v1.0.0 (proc-macro) ├── pm_target v1.0.0 (proc-macro) @@ -468,15 +454,14 @@ foo v0.1.0 ([..]/foo) └── build_target_dep v1.0.0 [dev-dependencies] └── devdep v1.0.0 -", - ) + +"#]]) .run(); // no-proc-macro p.cargo("tree --target=all -e no-proc-macro") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) ├── hostdep v1.0.0 └── targetdep v1.0.0 [build-dependencies] @@ -486,8 +471,8 @@ foo v0.1.0 ([..]/foo) └── build_target_dep v1.0.0 [dev-dependencies] └── devdep v1.0.0 -", - ) + +"#]]) .run(); } @@ -520,30 +505,26 @@ fn no_selected_target_dependency() { .build(); p.cargo("tree") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) -", - ) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) + +"#]]) .run(); p.cargo("tree -i targetdep") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [WARNING] nothing to print. -To find dependencies that require specific target platforms, \ -try to use option `--target all` first, and then narrow your search scope accordingly. -", - ) +To find dependencies that require specific target platforms, try to use option `--target all` first, and then narrow your search scope accordingly. + +"#]]) .run(); p.cargo("tree -i targetdep --target all") - .with_stdout( - "\ + .with_stdout_data(str![[r#" targetdep v1.0.0 -└── foo v0.1.0 ([..]/foo) -", - ) +└── foo v0.1.0 ([ROOT]/foo) + +"#]]) .run(); } @@ -595,9 +576,8 @@ fn dep_kinds() { .build(); p.cargo("tree") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) └── normaldep v1.0.0 └── inner-normal v1.0.0 [build-dependencies] @@ -614,14 +594,13 @@ foo v0.1.0 ([..]/foo) [build-dependencies] ├── inner-builddep v1.0.0 └── inner-buildpm v1.0.0 (proc-macro) -", - ) + +"#]]) .run(); p.cargo("tree -e no-dev") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) └── normaldep v1.0.0 └── inner-normal v1.0.0 [build-dependencies] @@ -631,24 +610,22 @@ foo v0.1.0 ([..]/foo) └── inner-normal v1.0.0 [build-dependencies] └── inner-builddep v1.0.0 -", - ) + +"#]]) .run(); p.cargo("tree -e normal") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) └── normaldep v1.0.0 └── inner-normal v1.0.0 -", - ) + +"#]]) .run(); p.cargo("tree -e dev,build") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) [build-dependencies] └── builddep v1.0.0 [build-dependencies] @@ -658,14 +635,13 @@ foo v0.1.0 ([..]/foo) [build-dependencies] ├── inner-builddep v1.0.0 └── inner-buildpm v1.0.0 (proc-macro) -", - ) + +"#]]) .run(); p.cargo("tree -e dev,build,no-proc-macro") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) [build-dependencies] └── builddep v1.0.0 [build-dependencies] @@ -674,8 +650,8 @@ foo v0.1.0 ([..]/foo) └── devdep v1.0.0 [build-dependencies] └── inner-builddep v1.0.0 -", - ) + +"#]]) .run(); } @@ -710,25 +686,23 @@ fn cyclic_dev_dep() { .build(); p.cargo("tree") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) [dev-dependencies] -└── dev-dep v0.1.0 ([..]/foo/dev-dep) - └── foo v0.1.0 ([..]/foo) (*) -", - ) +└── dev-dep v0.1.0 ([ROOT]/foo/dev-dep) + └── foo v0.1.0 ([ROOT]/foo) (*) + +"#]]) .run(); p.cargo("tree --invert foo") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) -└── dev-dep v0.1.0 ([..]/foo/dev-dep) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) +└── dev-dep v0.1.0 ([ROOT]/foo/dev-dep) [dev-dependencies] - └── foo v0.1.0 ([..]/foo) (*) -", - ) + └── foo v0.1.0 ([ROOT]/foo) (*) + +"#]]) .run(); } @@ -756,27 +730,25 @@ fn invert() { .build(); p.cargo("tree") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) ├── b1 v1.0.0 │ └── c v1.0.0 ├── b2 v1.0.0 │ └── d v1.0.0 └── c v1.0.0 -", - ) + +"#]]) .run(); p.cargo("tree --invert c") - .with_stdout( - "\ + .with_stdout_data(str![[r#" c v1.0.0 ├── b1 v1.0.0 -│ └── foo v0.1.0 ([..]/foo) -└── foo v0.1.0 ([..]/foo) -", - ) +│ └── foo v0.1.0 ([ROOT]/foo) +└── foo v0.1.0 ([ROOT]/foo) + +"#]]) .run(); } @@ -804,27 +776,25 @@ fn invert_with_build_dep() { .build(); p.cargo("tree") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) └── common v1.0.0 [build-dependencies] └── bdep v1.0.0 └── common v1.0.0 -", - ) + +"#]]) .run(); p.cargo("tree -i common") - .with_stdout( - "\ + .with_stdout_data(str![[r#" common v1.0.0 ├── bdep v1.0.0 │ [build-dependencies] -│ └── foo v0.1.0 ([..]/foo) -└── foo v0.1.0 ([..]/foo) -", - ) +│ └── foo v0.1.0 ([ROOT]/foo) +└── foo v0.1.0 ([ROOT]/foo) + +"#]]) .run(); } @@ -833,9 +803,8 @@ fn no_indent() { let p = make_simple_proj(); p.cargo("tree --prefix=none") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) a v1.0.0 b v1.0.0 c v1.0.0 @@ -844,8 +813,8 @@ bdep v1.0.0 b v1.0.0 (*) devdep v1.0.0 b v1.0.0 (*) -", - ) + +"#]]) .run(); } @@ -854,9 +823,8 @@ fn prefix_depth() { let p = make_simple_proj(); p.cargo("tree --prefix=depth") - .with_stdout( - "\ -0foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +0foo v0.1.0 ([ROOT]/foo) 1a v1.0.0 2b v1.0.0 3c v1.0.0 @@ -865,8 +833,8 @@ fn prefix_depth() { 2b v1.0.0 (*) 1devdep v1.0.0 2b v1.0.0 (*) -", - ) + +"#]]) .run(); } @@ -875,9 +843,8 @@ fn no_dedupe() { let p = make_simple_proj(); p.cargo("tree --no-dedupe") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) ├── a v1.0.0 │ └── b v1.0.0 │ └── c v1.0.0 @@ -890,8 +857,8 @@ foo v0.1.0 ([..]/foo) └── devdep v1.0.0 └── b v1.0.0 └── c v1.0.0 -", - ) + +"#]]) .run(); } @@ -926,25 +893,23 @@ fn no_dedupe_cycle() { .build(); p.cargo("tree") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) [dev-dependencies] -└── bar v0.1.0 ([..]/foo/bar) - └── foo v0.1.0 ([..]/foo) (*) -", - ) +└── bar v0.1.0 ([ROOT]/foo/bar) + └── foo v0.1.0 ([ROOT]/foo) (*) + +"#]]) .run(); p.cargo("tree --no-dedupe") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) [dev-dependencies] -└── bar v0.1.0 ([..]/foo/bar) - └── foo v0.1.0 ([..]/foo) (*) -", - ) +└── bar v0.1.0 ([ROOT]/foo/bar) + └── foo v0.1.0 ([ROOT]/foo) (*) + +"#]]) .run(); } @@ -995,50 +960,46 @@ fn duplicates() { .build(); p.cargo("tree -p a") - .with_stdout( - "\ -a v0.1.0 ([..]/foo/a) + .with_stdout_data(str![[r#" +a v0.1.0 ([ROOT]/foo/a) ├── dog v1.0.0 └── dog v2.0.0 -", - ) + +"#]]) .run(); p.cargo("tree -p b") - .with_stdout( - "\ -b v0.1.0 ([..]/foo/b) + .with_stdout_data(str![[r#" +b v0.1.0 ([ROOT]/foo/b) ├── cat v2.0.0 └── dep v1.0.0 ├── cat v1.0.0 └── dog v1.0.0 -", - ) + +"#]]) .run(); p.cargo("tree -p a -d") - .with_stdout( - "\ + .with_stdout_data(str![[r#" dog v1.0.0 -└── a v0.1.0 ([..]/foo/a) +└── a v0.1.0 ([ROOT]/foo/a) dog v2.0.0 -└── a v0.1.0 ([..]/foo/a) -", - ) +└── a v0.1.0 ([ROOT]/foo/a) + +"#]]) .run(); p.cargo("tree -p b -d") - .with_stdout( - "\ + .with_stdout_data(str![[r#" cat v1.0.0 └── dep v1.0.0 - └── b v0.1.0 ([..]/foo/b) + └── b v0.1.0 ([ROOT]/foo/b) cat v2.0.0 -└── b v0.1.0 ([..]/foo/b) -", - ) +└── b v0.1.0 ([ROOT]/foo/b) + +"#]]) .run(); } @@ -1072,19 +1033,21 @@ fn duplicates_with_target() { .file("src/lib.rs", "") .file("build.rs", "fn main() {}") .build(); - p.cargo("tree -d").with_stdout("").run(); + p.cargo("tree -d").with_stdout_data(str![""]).run(); p.cargo("tree -d --target") .arg(alternate()) - .with_stdout("") + .with_stdout_data(str![""]) .run(); p.cargo("tree -d --target") .arg(rustc_host()) - .with_stdout("") + .with_stdout_data(str![""]) .run(); - p.cargo("tree -d --target=all").with_stdout("").run(); + p.cargo("tree -d --target=all") + .with_stdout_data(str![""]) + .run(); } #[cargo_test] @@ -1112,31 +1075,29 @@ fn duplicates_with_proc_macro() { .build(); p.cargo("tree") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) ├── dupe-dep v2.0.0 └── proc v1.0.0 (proc-macro) └── dupe-dep v1.0.0 -", - ) + +"#]]) .run(); p.cargo("tree --duplicates") - .with_stdout( - "\ + .with_stdout_data(str![[r#" dupe-dep v1.0.0 └── proc v1.0.0 (proc-macro) - └── foo v0.1.0 ([..]/foo) + └── foo v0.1.0 ([ROOT]/foo) dupe-dep v2.0.0 -└── foo v0.1.0 ([..]/foo) -", - ) +└── foo v0.1.0 ([ROOT]/foo) + +"#]]) .run(); p.cargo("tree --duplicates --edges no-proc-macro") - .with_stdout("") + .with_stdout_data(str![""]) .run(); } @@ -1144,9 +1105,8 @@ dupe-dep v2.0.0 fn charset() { let p = make_simple_proj(); p.cargo("tree --charset ascii") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) |-- a v1.0.0 | `-- b v1.0.0 | `-- c v1.0.0 @@ -1157,8 +1117,8 @@ foo v0.1.0 ([..]/foo) [dev-dependencies] `-- devdep v1.0.0 `-- b v1.0.0 (*) -", - ) + +"#]]) .run(); } @@ -1208,56 +1168,66 @@ fn format() { .build(); p.cargo("tree --format <<<{p}>>>") - .with_stdout("<<>>") + .with_stdout_data(str![[r#" +<<>> + +"#]]) .run(); p.cargo("tree --format {}") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [ERROR] tree format `{}` not valid Caused by: unsupported pattern `` -", - ) + +"#]]) .with_status(101) .run(); p.cargo("tree --format {p}-{{hello}}") - .with_stdout("foo v0.1.0 ([..]/foo)-{hello}") + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo)-{hello} + +"#]]) .run(); p.cargo("tree --format") .arg("{p} {l} {r}") - .with_stdout("foo v0.1.0 ([..]/foo) MIT https://github.com/rust-lang/cargo") + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) MIT https://github.com/rust-lang/cargo + +"#]]) .run(); p.cargo("tree --format") .arg("{p} {f}") - .with_stdout("foo v0.1.0 ([..]/foo) bar,default,foo") + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) bar,default,foo + +"#]]) .run(); p.cargo("tree --all-features --format") .arg("{p} [{f}]") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) [bar,default,dep,dep_that_is_awesome,foo,other-dep] + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) [bar,default,dep,dep_that_is_awesome,foo,other-dep] ├── dep v1.0.0 [] ├── dep_that_is_awesome v1.0.0 [] └── other-dep v1.0.0 [] -", - ) + +"#]]) .run(); p.cargo("tree") .arg("--features=other-dep,dep_that_is_awesome") .arg("--format={lib}") - .with_stdout( - " + .with_stdout_data(str![[r#" + ├── awesome_dep └── other_dep -", - ) + +"#]]) .run(); } @@ -1288,49 +1258,45 @@ fn dev_dep_feature() { // Old behavior. p.cargo("tree") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) └── bar v1.0.0 └── optdep v1.0.0 [dev-dependencies] └── bar v1.0.0 (*) -", - ) + +"#]]) .run(); p.cargo("tree -e normal") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) └── bar v1.0.0 └── optdep v1.0.0 -", - ) + +"#]]) .run(); // New behavior. switch_to_resolver_2(&p); p.cargo("tree") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) └── bar v1.0.0 └── optdep v1.0.0 [dev-dependencies] └── bar v1.0.0 (*) -", - ) + +"#]]) .run(); p.cargo("tree -e normal") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) └── bar v1.0.0 -", - ) + +"#]]) .run(); } @@ -1362,89 +1328,82 @@ fn host_dep_feature() { // Old behavior p.cargo("tree") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) └── bar v1.0.0 └── optdep v1.0.0 [build-dependencies] └── bar v1.0.0 (*) -", - ) + +"#]]) .run(); // -p p.cargo("tree -p bar") - .with_stdout( - "\ + .with_stdout_data(str![[r#" bar v1.0.0 └── optdep v1.0.0 -", - ) + +"#]]) .run(); // invert p.cargo("tree -i optdep") - .with_stdout( - "\ + .with_stdout_data(str![[r#" optdep v1.0.0 └── bar v1.0.0 - └── foo v0.1.0 ([..]/foo) + └── foo v0.1.0 ([ROOT]/foo) [build-dependencies] - └── foo v0.1.0 ([..]/foo) -", - ) + └── foo v0.1.0 ([ROOT]/foo) + +"#]]) .run(); // New behavior. switch_to_resolver_2(&p); p.cargo("tree") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) └── bar v1.0.0 [build-dependencies] └── bar v1.0.0 └── optdep v1.0.0 -", - ) + +"#]]) .run(); p.cargo("tree -p bar") - .with_stdout( - "\ + .with_stdout_data(str![[r#" bar v1.0.0 bar v1.0.0 └── optdep v1.0.0 -", - ) + +"#]]) .run(); p.cargo("tree -i optdep") - .with_stdout( - "\ + .with_stdout_data(str![[r#" optdep v1.0.0 └── bar v1.0.0 [build-dependencies] - └── foo v0.1.0 ([..]/foo) -", - ) + └── foo v0.1.0 ([ROOT]/foo) + +"#]]) .run(); // Check that -d handles duplicates with features. p.cargo("tree -d") - .with_stdout( - "\ + .with_stdout_data(str![[r#" bar v1.0.0 -└── foo v0.1.0 ([..]/foo) +└── foo v0.1.0 ([ROOT]/foo) bar v1.0.0 [build-dependencies] -└── foo v0.1.0 ([..]/foo) -", - ) +└── foo v0.1.0 ([ROOT]/foo) + +"#]]) .run(); } @@ -1477,68 +1436,62 @@ fn proc_macro_features() { // Old behavior p.cargo("tree") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) ├── pm v1.0.0 (proc-macro) │ └── somedep v1.0.0 │ └── optdep v1.0.0 └── somedep v1.0.0 (*) -", - ) + +"#]]) .run(); // Old behavior + no-proc-macro p.cargo("tree -e no-proc-macro") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) └── somedep v1.0.0 └── optdep v1.0.0 -", - ) + +"#]]) .run(); // -p p.cargo("tree -p somedep") - .with_stdout( - "\ + .with_stdout_data(str![[r#" somedep v1.0.0 └── optdep v1.0.0 -", - ) + +"#]]) .run(); // -p -e no-proc-macro p.cargo("tree -p somedep -e no-proc-macro") - .with_stdout( - "\ + .with_stdout_data(str![[r#" somedep v1.0.0 └── optdep v1.0.0 -", - ) + +"#]]) .run(); // invert p.cargo("tree -i somedep") - .with_stdout( - "\ + .with_stdout_data(str![[r#" somedep v1.0.0 -├── foo v0.1.0 ([..]/foo) +├── foo v0.1.0 ([ROOT]/foo) └── pm v1.0.0 (proc-macro) - └── foo v0.1.0 ([..]/foo) -", - ) + └── foo v0.1.0 ([ROOT]/foo) + +"#]]) .run(); // invert + no-proc-macro p.cargo("tree -i somedep -e no-proc-macro") - .with_stdout( - "\ + .with_stdout_data(str![[r#" somedep v1.0.0 -└── foo v0.1.0 ([..]/foo) -", - ) +└── foo v0.1.0 ([ROOT]/foo) + +"#]]) .run(); // New behavior. @@ -1546,57 +1499,52 @@ somedep v1.0.0 // Note the missing (*) p.cargo("tree") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) ├── pm v1.0.0 (proc-macro) │ └── somedep v1.0.0 │ └── optdep v1.0.0 └── somedep v1.0.0 -", - ) + +"#]]) .run(); p.cargo("tree -e no-proc-macro") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) └── somedep v1.0.0 -", - ) + +"#]]) .run(); p.cargo("tree -p somedep") - .with_stdout( - "\ + .with_stdout_data(str![[r#" somedep v1.0.0 somedep v1.0.0 └── optdep v1.0.0 -", - ) + +"#]]) .run(); p.cargo("tree -i somedep") - .with_stdout( - "\ + .with_stdout_data(str![[r#" somedep v1.0.0 -└── foo v0.1.0 ([..]/foo) +└── foo v0.1.0 ([ROOT]/foo) somedep v1.0.0 └── pm v1.0.0 (proc-macro) - └── foo v0.1.0 ([..]/foo) -", - ) + └── foo v0.1.0 ([ROOT]/foo) + +"#]]) .run(); p.cargo("tree -i somedep -e no-proc-macro") - .with_stdout( - "\ + .with_stdout_data(str![[r#" somedep v1.0.0 -└── foo v0.1.0 ([..]/foo) -", - ) +└── foo v0.1.0 ([ROOT]/foo) + +"#]]) .run(); } @@ -1629,25 +1577,23 @@ fn itarget_opt_dep() { // Old behavior p.cargo("tree") - .with_stdout( - "\ -foo v1.0.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v1.0.0 ([ROOT]/foo) └── common v1.0.0 └── optdep v1.0.0 -", - ) + +"#]]) .run(); // New behavior. switch_to_resolver_2(&p); p.cargo("tree") - .with_stdout( - "\ -foo v1.0.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v1.0.0 ([ROOT]/foo) └── common v1.0.0 -", - ) + +"#]]) .run(); } @@ -1674,14 +1620,20 @@ fn ambiguous_name() { .build(); p.cargo("tree -p dep") - .with_stderr_contains( - "\ -error: There are multiple `dep` packages in your project, and the specification `dep` is ambiguous. + .with_stderr_data(str![[r#" +[UPDATING] `dummy-registry` index +[LOCKING] 4 packages to latest compatible versions +[ADDING] dep v1.0.0 (latest: v2.0.0) +[DOWNLOADING] crates ... +[DOWNLOADED] dep v2.0.0 (registry `dummy-registry`) +[DOWNLOADED] dep v1.0.0 (registry `dummy-registry`) +[DOWNLOADED] bar v1.0.0 (registry `dummy-registry`) +[ERROR] There are multiple `dep` packages in your project, and the specification `dep` is ambiguous. Please re-run this command with one of the following specifications: dep@1.0.0 dep@2.0.0 -", - ) + +"#]]) .with_status(101) .run(); } @@ -1723,41 +1675,39 @@ fn workspace_features_are_local() { [dependencies] somedep = "1.0" + "#, ) .file("b/src/lib.rs", "") .build(); p.cargo("tree") - .with_stdout( - "\ -a v0.1.0 ([..]/foo/a) + .with_stdout_data(str![[r#" +a v0.1.0 ([ROOT]/foo/a) └── somedep v1.0.0 └── optdep v1.0.0 -b v0.1.0 ([..]/foo/b) +b v0.1.0 ([ROOT]/foo/b) └── somedep v1.0.0 (*) -", - ) + +"#]]) .run(); p.cargo("tree -p a") - .with_stdout( - "\ -a v0.1.0 ([..]/foo/a) + .with_stdout_data(str![[r#" +a v0.1.0 ([ROOT]/foo/a) └── somedep v1.0.0 └── optdep v1.0.0 -", - ) + +"#]]) .run(); p.cargo("tree -p b") - .with_stdout( - "\ -b v0.1.0 ([..]/foo/b) + .with_stdout_data(str![[r#" +b v0.1.0 ([ROOT]/foo/b) └── somedep v1.0.0 -", - ) + +"#]]) .run(); } @@ -1769,14 +1719,10 @@ fn unknown_edge_kind() { .build(); p.cargo("tree -e unknown") - .with_stderr( - "\ -[ERROR] unknown edge kind `unknown`, valid values are \ -\"normal\", \"build\", \"dev\", \ -\"no-normal\", \"no-build\", \"no-dev\", \"no-proc-macro\", \ -\"features\", or \"all\" -", - ) + .with_stderr_data(str![[r#" +[ERROR] unknown edge kind `unknown`, valid values are "normal", "build", "dev", "no-normal", "no-build", "no-dev", "no-proc-macro", "features", or "all" + +"#]]) .with_status(101) .run(); } @@ -1796,22 +1742,19 @@ fn mixed_no_edge_kinds() { .build(); p.cargo("tree -e no-build,normal") - .with_stderr( - "\ -[ERROR] `normal` dependency kind cannot be mixed with \ -\"no-normal\", \"no-build\", or \"no-dev\" dependency kinds -", - ) + .with_stderr_data(str![[r#" +[ERROR] `normal` dependency kind cannot be mixed with "no-normal", "no-build", or "no-dev" dependency kinds + +"#]]) .with_status(101) .run(); // `no-proc-macro` can be mixed with others p.cargo("tree -e no-proc-macro,normal") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) -", - ) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) + +"#]]) .run(); } @@ -1820,33 +1763,30 @@ fn depth_limit() { let p = make_simple_proj(); p.cargo("tree --depth 0") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) [build-dependencies] [dev-dependencies] -", - ) + +"#]]) .run(); p.cargo("tree --depth 1") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) ├── a v1.0.0 └── c v1.0.0 [build-dependencies] └── bdep v1.0.0 [dev-dependencies] └── devdep v1.0.0 -", - ) + +"#]]) .run(); p.cargo("tree --depth 2") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) ├── a v1.0.0 │ └── b v1.0.0 └── c v1.0.0 @@ -1856,55 +1796,51 @@ foo v0.1.0 ([..]/foo) [dev-dependencies] └── devdep v1.0.0 └── b v1.0.0 (*) -", - ) + +"#]]) .run(); // specify a package p.cargo("tree -p bdep --depth 1") - .with_stdout( - "\ + .with_stdout_data(str![[r#" bdep v1.0.0 └── b v1.0.0 -", - ) + +"#]]) .run(); // different prefix p.cargo("tree --depth 1 --prefix depth") - .with_stdout( - "\ -0foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +0foo v0.1.0 ([ROOT]/foo) 1a v1.0.0 1c v1.0.0 1bdep v1.0.0 1devdep v1.0.0 -", - ) + +"#]]) .run(); // with edge-kinds p.cargo("tree --depth 1 -e no-dev") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) ├── a v1.0.0 └── c v1.0.0 [build-dependencies] └── bdep v1.0.0 -", - ) + +"#]]) .run(); // invert p.cargo("tree --depth 1 --invert c") - .with_stdout( - "\ + .with_stdout_data(str![[r#" c v1.0.0 ├── b v1.0.0 -└── foo v0.1.0 ([..]/foo) -", - ) +└── foo v0.1.0 ([ROOT]/foo) + +"#]]) .run(); } @@ -1913,9 +1849,8 @@ fn prune() { let p = make_simple_proj(); p.cargo("tree --prune c") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) └── a v1.0.0 └── b v1.0.0 [build-dependencies] @@ -1924,41 +1859,38 @@ foo v0.1.0 ([..]/foo) [dev-dependencies] └── devdep v1.0.0 └── b v1.0.0 (*) -", - ) + +"#]]) .run(); // multiple prune p.cargo("tree --prune c --prune bdep") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) └── a v1.0.0 └── b v1.0.0 [build-dependencies] [dev-dependencies] └── devdep v1.0.0 └── b v1.0.0 (*) -", - ) + +"#]]) .run(); // with edge-kinds p.cargo("tree --prune c -e normal") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) └── a v1.0.0 └── b v1.0.0 -", - ) + +"#]]) .run(); // pruning self does not works p.cargo("tree --prune foo") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) ├── a v1.0.0 │ └── b v1.0.0 │ └── c v1.0.0 @@ -1969,19 +1901,18 @@ foo v0.1.0 ([..]/foo) [dev-dependencies] └── devdep v1.0.0 └── b v1.0.0 (*) -", - ) + +"#]]) .run(); // dep not exist p.cargo("tree --prune no-dep") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [ERROR] package ID specification `no-dep` did not match any packages -Did you mean `bdep`? -", - ) + Did you mean `bdep`? + +"#]]) .with_status(101) .run(); } @@ -2007,21 +1938,23 @@ fn cyclic_features() { .build(); p.cargo("tree -e features") - .with_stdout("foo v1.0.0 ([ROOT]/foo)") + .with_stdout_data(str![[r#" +foo v1.0.0 ([ROOT]/foo) + +"#]]) .run(); p.cargo("tree -e features -i foo") - .with_stdout( - "\ + .with_stdout_data(str![[r#" foo v1.0.0 ([ROOT]/foo) -├── foo feature \"a\" -│ ├── foo feature \"b\" -│ │ └── foo feature \"a\" (*) -│ └── foo feature \"default\" (command-line) -├── foo feature \"b\" (*) -└── foo feature \"default\" (command-line) -", - ) +├── foo feature "a" +│ ├── foo feature "b" +│ │ └── foo feature "a" (*) +│ └── foo feature "default" (command-line) +├── foo feature "b" (*) +└── foo feature "default" (command-line) + +"#]]) .run(); } @@ -2062,33 +1995,31 @@ fn dev_dep_cycle_with_feature() { .build(); p.cargo("tree -e features --features a") - .with_stdout( - "\ + .with_stdout_data(str![[r#" foo v1.0.0 ([ROOT]/foo) [dev-dependencies] -└── bar feature \"default\" +└── bar feature "default" └── bar v1.0.0 ([ROOT]/foo/bar) - └── foo feature \"default\" (command-line) + └── foo feature "default" (command-line) └── foo v1.0.0 ([ROOT]/foo) (*) -", - ) + +"#]]) .run(); p.cargo("tree -e features --features a -i foo") - .with_stdout( - "\ + .with_stdout_data(str![[r#" foo v1.0.0 ([ROOT]/foo) -├── foo feature \"a\" (command-line) -│ └── bar feature \"feat1\" -│ └── foo feature \"a\" (command-line) (*) -└── foo feature \"default\" (command-line) +├── foo feature "a" (command-line) +│ └── bar feature "feat1" +│ └── foo feature "a" (command-line) (*) +└── foo feature "default" (command-line) └── bar v1.0.0 ([ROOT]/foo/bar) - ├── bar feature \"default\" + ├── bar feature "default" │ [dev-dependencies] │ └── foo v1.0.0 ([ROOT]/foo) (*) - └── bar feature \"feat1\" (*) -", - ) + └── bar feature "feat1" (*) + +"#]]) .run(); } @@ -2132,72 +2063,68 @@ fn dev_dep_cycle_with_feature_nested() { .build(); p.cargo("tree -e features") - .with_stdout( - "\ + .with_stdout_data(str![[r#" foo v1.0.0 ([ROOT]/foo) [dev-dependencies] -└── bar feature \"default\" +└── bar feature "default" └── bar v1.0.0 ([ROOT]/foo/bar) - └── foo feature \"default\" (command-line) + └── foo feature "default" (command-line) └── foo v1.0.0 ([ROOT]/foo) (*) -", - ) + +"#]]) .run(); p.cargo("tree -e features --features a -i foo") - .with_stdout( - "\ + .with_stdout_data(str![[r#" foo v1.0.0 ([ROOT]/foo) -├── foo feature \"a\" (command-line) -│ └── foo feature \"b\" -│ └── bar feature \"feat1\" -│ └── foo feature \"a\" (command-line) (*) -├── foo feature \"b\" (*) -└── foo feature \"default\" (command-line) +├── foo feature "a" (command-line) +│ └── foo feature "b" +│ └── bar feature "feat1" +│ └── foo feature "a" (command-line) (*) +├── foo feature "b" (*) +└── foo feature "default" (command-line) └── bar v1.0.0 ([ROOT]/foo/bar) - ├── bar feature \"default\" + ├── bar feature "default" │ [dev-dependencies] │ └── foo v1.0.0 ([ROOT]/foo) (*) - └── bar feature \"feat1\" (*) -", - ) + └── bar feature "feat1" (*) + +"#]]) .run(); p.cargo("tree -e features --features b -i foo") - .with_stdout( - "\ + .with_stdout_data(str![[r#" foo v1.0.0 ([ROOT]/foo) -├── foo feature \"a\" -│ └── foo feature \"b\" (command-line) -│ └── bar feature \"feat1\" -│ └── foo feature \"a\" (*) -├── foo feature \"b\" (command-line) (*) -└── foo feature \"default\" (command-line) +├── foo feature "a" +│ └── foo feature "b" (command-line) +│ └── bar feature "feat1" +│ └── foo feature "a" (*) +├── foo feature "b" (command-line) (*) +└── foo feature "default" (command-line) └── bar v1.0.0 ([ROOT]/foo/bar) - ├── bar feature \"default\" + ├── bar feature "default" │ [dev-dependencies] │ └── foo v1.0.0 ([ROOT]/foo) (*) - └── bar feature \"feat1\" (*) -", - ) + └── bar feature "feat1" (*) + +"#]]) .run(); p.cargo("tree -e features --features bar/feat1 -i foo") - .with_stdout( - "\ + .with_stdout_data(str![[r#" foo v1.0.0 ([ROOT]/foo) -├── foo feature \"a\" -│ └── foo feature \"b\" -│ └── bar feature \"feat1\" (command-line) -│ └── foo feature \"a\" (*) -├── foo feature \"b\" (*) -└── foo feature \"default\" (command-line) +├── foo feature "a" +│ └── foo feature "b" +│ └── bar feature "feat1" (command-line) +│ └── foo feature "a" (*) +├── foo feature "b" (*) +└── foo feature "default" (command-line) └── bar v1.0.0 ([ROOT]/foo/bar) - ├── bar feature \"default\" + ├── bar feature "default" │ [dev-dependencies] │ └── foo v1.0.0 ([ROOT]/foo) (*) - └── bar feature \"feat1\" (command-line) (*) -", - ) + └── bar feature "feat1" (command-line) (*) + +"#]]) .run(); } From 3308d308a2229bef0878669b06c251076ec9a347 Mon Sep 17 00:00:00 2001 From: eth3lbert Date: Tue, 18 Jun 2024 15:57:42 +0800 Subject: [PATCH 5/7] test: migrate tree_graph_features to snapbox --- tests/testsuite/tree_graph_features.rs | 253 ++++++++++++------------- 1 file changed, 120 insertions(+), 133 deletions(-) diff --git a/tests/testsuite/tree_graph_features.rs b/tests/testsuite/tree_graph_features.rs index 1d4d47a08ac4..34db61cc2caf 100644 --- a/tests/testsuite/tree_graph_features.rs +++ b/tests/testsuite/tree_graph_features.rs @@ -1,9 +1,8 @@ //! Tests for the `cargo tree` command with -e features option. -#![allow(deprecated)] - use cargo_test_support::project; use cargo_test_support::registry::{Dependency, Package}; +use cargo_test_support::str; #[cargo_test] fn dep_feature_various() { @@ -52,41 +51,40 @@ fn dep_feature_various() { .build(); p.cargo("tree -e features") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) ├── nodefaultdep v1.0.0 -├── defaultdep feature \"default\" +├── defaultdep feature "default" │ ├── defaultdep v1.0.0 -│ │ └── optdep feature \"default\" +│ │ └── optdep feature "default" │ │ ├── optdep v1.0.0 -│ │ └── optdep feature \"cat\" +│ │ └── optdep feature "cat" │ │ └── optdep v1.0.0 -│ └── defaultdep feature \"f1\" +│ └── defaultdep feature "f1" │ ├── defaultdep v1.0.0 (*) -│ └── defaultdep feature \"optdep\" +│ └── defaultdep feature "optdep" │ └── defaultdep v1.0.0 (*) -├── nameddep feature \"default\" +├── nameddep feature "default" │ ├── nameddep v1.0.0 -│ │ └── serde feature \"default\" +│ │ └── serde feature "default" │ │ └── serde v1.0.0 -│ │ └── serde_derive feature \"default\" +│ │ └── serde_derive feature "default" │ │ └── serde_derive v1.0.0 -│ └── nameddep feature \"serde-stuff\" +│ └── nameddep feature "serde-stuff" │ ├── nameddep v1.0.0 (*) -│ ├── nameddep feature \"serde\" +│ ├── nameddep feature "serde" │ │ └── nameddep v1.0.0 (*) -│ └── serde feature \"derive\" +│ └── serde feature "derive" │ ├── serde v1.0.0 (*) -│ └── serde feature \"serde_derive\" +│ └── serde feature "serde_derive" │ └── serde v1.0.0 (*) -├── nameddep feature \"serde\" (*) -└── nameddep feature \"vehicle\" +├── nameddep feature "serde" (*) +└── nameddep feature "vehicle" ├── nameddep v1.0.0 (*) - └── nameddep feature \"car\" + └── nameddep feature "car" └── nameddep v1.0.0 (*) -", - ) + +"#]]) .run(); } @@ -135,38 +133,36 @@ fn graph_features_ws_interdependent() { .build(); p.cargo("tree -e features") - .with_stdout( - "\ -a v0.1.0 ([..]/foo/a) -├── b feature \"default\" (command-line) -│ ├── b v0.1.0 ([..]/foo/b) -│ └── b feature \"feat1\" -│ └── b v0.1.0 ([..]/foo/b) -└── b feature \"feat2\" - └── b v0.1.0 ([..]/foo/b) - -b v0.1.0 ([..]/foo/b) -", - ) + .with_stdout_data(str![[r#" +a v0.1.0 ([ROOT]/foo/a) +├── b feature "default" (command-line) +│ ├── b v0.1.0 ([ROOT]/foo/b) +│ └── b feature "feat1" +│ └── b v0.1.0 ([ROOT]/foo/b) +└── b feature "feat2" + └── b v0.1.0 ([ROOT]/foo/b) + +b v0.1.0 ([ROOT]/foo/b) + +"#]]) .run(); p.cargo("tree -e features -i a -i b") - .with_stdout( - "\ -a v0.1.0 ([..]/foo/a) -├── a feature \"a1\" -│ └── a feature \"default\" (command-line) -└── a feature \"default\" (command-line) - -b v0.1.0 ([..]/foo/b) -├── b feature \"default\" (command-line) -│ └── a v0.1.0 ([..]/foo/a) (*) -├── b feature \"feat1\" -│ └── b feature \"default\" (command-line) (*) -└── b feature \"feat2\" - └── a v0.1.0 ([..]/foo/a) (*) -", - ) + .with_stdout_data(str![[r#" +a v0.1.0 ([ROOT]/foo/a) +├── a feature "a1" +│ └── a feature "default" (command-line) +└── a feature "default" (command-line) + +b v0.1.0 ([ROOT]/foo/b) +├── b feature "default" (command-line) +│ └── a v0.1.0 ([ROOT]/foo/a) (*) +├── b feature "feat1" +│ └── b feature "default" (command-line) (*) +└── b feature "feat2" + └── a v0.1.0 ([ROOT]/foo/a) (*) + +"#]]) .run(); } @@ -202,90 +198,84 @@ fn slash_feature_name() { .build(); p.cargo("tree -e features --features f1") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) -├── notopt feature \"default\" + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) +├── notopt feature "default" │ └── notopt v1.0.0 -└── opt feature \"default\" +└── opt feature "default" └── opt v1.0.0 -", - ) + +"#]]) .run(); p.cargo("tree -e features --features f1 -i foo") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) -├── foo feature \"default\" (command-line) -├── foo feature \"f1\" (command-line) -└── foo feature \"opt\" - └── foo feature \"f1\" (command-line) -", - ) + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) +├── foo feature "default" (command-line) +├── foo feature "f1" (command-line) +└── foo feature "opt" + └── foo feature "f1" (command-line) + +"#]]) .run(); p.cargo("tree -e features --features f1 -i notopt") - .with_stdout( - "\ + .with_stdout_data(str![[r#" notopt v1.0.0 -├── notopt feature \"animal\" -│ └── foo feature \"f1\" (command-line) -├── notopt feature \"cat\" -│ └── notopt feature \"animal\" (*) -└── notopt feature \"default\" - └── foo v0.1.0 ([..]/foo) - ├── foo feature \"default\" (command-line) - ├── foo feature \"f1\" (command-line) - └── foo feature \"opt\" - └── foo feature \"f1\" (command-line) -", - ) +├── notopt feature "animal" +│ └── foo feature "f1" (command-line) +├── notopt feature "cat" +│ └── notopt feature "animal" (*) +└── notopt feature "default" + └── foo v0.1.0 ([ROOT]/foo) + ├── foo feature "default" (command-line) + ├── foo feature "f1" (command-line) + └── foo feature "opt" + └── foo feature "f1" (command-line) + +"#]]) .run(); p.cargo("tree -e features --features notopt/animal -i notopt") - .with_stdout( - "\ + .with_stdout_data(str![[r#" notopt v1.0.0 -├── notopt feature \"animal\" (command-line) -├── notopt feature \"cat\" -│ └── notopt feature \"animal\" (command-line) -└── notopt feature \"default\" - └── foo v0.1.0 ([..]/foo) - └── foo feature \"default\" (command-line) -", - ) +├── notopt feature "animal" (command-line) +├── notopt feature "cat" +│ └── notopt feature "animal" (command-line) +└── notopt feature "default" + └── foo v0.1.0 ([ROOT]/foo) + └── foo feature "default" (command-line) + +"#]]) .run(); p.cargo("tree -e features --all-features") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) -├── notopt feature \"default\" + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) +├── notopt feature "default" │ └── notopt v1.0.0 -├── opt feature \"default\" +├── opt feature "default" │ └── opt v1.0.0 -└── opt2 feature \"default\" +└── opt2 feature "default" └── opt2 v1.0.0 -", - ) + +"#]]) .run(); p.cargo("tree -e features --all-features -i opt2") - .with_stdout( - "\ + .with_stdout_data(str![[r#" opt2 v1.0.0 -└── opt2 feature \"default\" - └── foo v0.1.0 ([..]/foo) - ├── foo feature \"default\" (command-line) - ├── foo feature \"f1\" (command-line) - │ └── foo feature \"f2\" (command-line) - ├── foo feature \"f2\" (command-line) - ├── foo feature \"opt\" (command-line) - │ └── foo feature \"f1\" (command-line) (*) - └── foo feature \"opt2\" (command-line) -", - ) +└── opt2 feature "default" + └── foo v0.1.0 ([ROOT]/foo) + ├── foo feature "default" (command-line) + ├── foo feature "f1" (command-line) + │ └── foo feature "f2" (command-line) + ├── foo feature "f2" (command-line) + ├── foo feature "opt" (command-line) + │ └── foo feature "f1" (command-line) (*) + └── foo feature "opt2" (command-line) + +"#]]) .run(); } @@ -330,35 +320,32 @@ fn features_enables_inactive_target() { .file("src/lib.rs", "") .build(); p.cargo("tree -e features") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) -└── dep2 feature \"default\" + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) +└── dep2 feature "default" └── dep2 v1.0.0 -", - ) + +"#]]) .run(); p.cargo("tree -e features --all-features") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) -└── dep2 feature \"default\" + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) +└── dep2 feature "default" └── dep2 v1.0.0 -", - ) + +"#]]) .run(); p.cargo("tree -e features --all-features --target=all") - .with_stdout( - "\ -foo v0.1.0 ([..]/foo) -├── dep1 feature \"default\" + .with_stdout_data(str![[r#" +foo v0.1.0 ([ROOT]/foo) +├── dep1 feature "default" │ └── dep1 v1.0.0 -├── dep2 feature \"default\" +├── dep2 feature "default" │ └── dep2 v1.0.0 -│ └── optdep feature \"default\" +│ └── optdep feature "default" │ └── optdep v1.0.0 -└── optdep feature \"default\" (*) -", - ) +└── optdep feature "default" (*) + +"#]]) .run(); } From 153856fe141108d7e10b2f67d82c8e5b1f3d7287 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Tue, 18 Jun 2024 13:58:13 -0400 Subject: [PATCH 6/7] test: prefer raw string for regex reduction --- crates/cargo-test-support/src/compare.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/cargo-test-support/src/compare.rs b/crates/cargo-test-support/src/compare.rs index 9a7f93bc557e..919e33be4608 100644 --- a/crates/cargo-test-support/src/compare.rs +++ b/crates/cargo-test-support/src/compare.rs @@ -149,32 +149,32 @@ fn add_common_redactions(subs: &mut snapbox::Redactions) { // For e2e tests subs.insert( "[ELAPSED]", - regex!("[FINISHED].*in (?[0-9]+(\\.[0-9]+))s"), + regex!(r"[FINISHED].*in (?[0-9]+(\.[0-9]+))s"), ) .unwrap(); // for UI tests subs.insert( "[ELAPSED]", - regex!("Finished.*in (?[0-9]+(\\.[0-9]+))s"), + regex!(r"Finished.*in (?[0-9]+(\.[0-9]+))s"), ) .unwrap(); // output from libtest subs.insert( "[ELAPSED]", - regex!("; finished in (?[0-9]+(\\.[0-9]+))s"), + regex!(r"; finished in (?[0-9]+(\.[0-9]+))s"), ) .unwrap(); subs.insert( "[FILE_SIZE]", - regex!("(?[0-9]+(\\.[0-9]+)([a-zA-Z]i)?)B"), + regex!(r"(?[0-9]+(\.[0-9]+)([a-zA-Z]i)?)B"), ) .unwrap(); subs.insert( "[HASH]", - regex!("home/\\.cargo/registry/src/-(?[a-z0-9]+)"), + regex!(r"home/\.cargo/registry/src/-(?[a-z0-9]+)"), ) .unwrap(); - subs.insert("[HASH]", regex!("/[a-z0-9\\-_]+-(?[0-9a-f]{16})")) + subs.insert("[HASH]", regex!(r"/[a-z0-9\-_]+-(?[0-9a-f]{16})")) .unwrap(); subs.insert("[HOST_TARGET]", rustc_host()).unwrap(); if let Some(alt_target) = try_alternate() { @@ -182,12 +182,12 @@ fn add_common_redactions(subs: &mut snapbox::Redactions) { } subs.insert( "[AVG_ELAPSED]", - regex!("(?[0-9]+(\\.[0-9]+)?) ns/iter"), + regex!(r"(?[0-9]+(\.[0-9]+)?) ns/iter"), ) .unwrap(); subs.insert( "[JITTER]", - regex!("ns/iter \\(\\+/- (?[0-9]+(\\.[0-9]+)?)\\)"), + regex!(r"ns/iter \(\+/- (?[0-9]+(\.[0-9]+)?)\)"), ) .unwrap(); } From 6a684edcb636a4b98755d9833fa31e79841df1fd Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Tue, 18 Jun 2024 13:58:56 -0400 Subject: [PATCH 7/7] test: fix the `[FINISHED]` escape --- crates/cargo-test-support/src/compare.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/cargo-test-support/src/compare.rs b/crates/cargo-test-support/src/compare.rs index 919e33be4608..22dadef53eff 100644 --- a/crates/cargo-test-support/src/compare.rs +++ b/crates/cargo-test-support/src/compare.rs @@ -149,7 +149,7 @@ fn add_common_redactions(subs: &mut snapbox::Redactions) { // For e2e tests subs.insert( "[ELAPSED]", - regex!(r"[FINISHED].*in (?[0-9]+(\.[0-9]+))s"), + regex!(r"\[FINISHED\].*in (?[0-9]+(\.[0-9]+))s"), ) .unwrap(); // for UI tests