From 2d23d031e382ab37506c43822923dd6776a4ab3d Mon Sep 17 00:00:00 2001 From: eth3lbert Date: Sat, 22 Jun 2024 13:15:42 +0800 Subject: [PATCH 1/4] test: migrate rename_deps to snapbox --- tests/testsuite/rename_deps.rs | 51 ++++++++++++++++------------------ 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/tests/testsuite/rename_deps.rs b/tests/testsuite/rename_deps.rs index b132082a4f8..06d9907a7d7 100644 --- a/tests/testsuite/rename_deps.rs +++ b/tests/testsuite/rename_deps.rs @@ -1,11 +1,9 @@ //! Tests for renaming dependencies. -#![allow(deprecated)] - use cargo_test_support::git; use cargo_test_support::paths; use cargo_test_support::registry::{self, Package}; -use cargo_test_support::{basic_manifest, project}; +use cargo_test_support::{basic_manifest, project, str}; #[cargo_test] fn rename_dependency() { @@ -191,15 +189,14 @@ fn rename_twice() { p.cargo("build -v") .with_status(101) - .with_stderr( - "\ -[UPDATING] `[..]` index + .with_stderr_data(str![[r#" +[UPDATING] `dummy-registry` index [LOCKING] 2 packages to latest compatible versions [DOWNLOADING] crates ... -[DOWNLOADED] foo v0.1.0 (registry [..]) -error: the crate `test v0.1.0 ([CWD])` depends on crate `foo v0.1.0` multiple times with different names -", - ) +[DOWNLOADED] foo v0.1.0 (registry `dummy-registry`) +[ERROR] the crate `test v0.1.0 ([ROOT]/foo)` depends on crate `foo v0.1.0` multiple times with different names + +"#]]) .run(); } @@ -242,7 +239,14 @@ fn rename_affects_fingerprint() { p.cargo("build -v") .with_status(101) - .with_stderr_contains("[..]can't find crate for `foo`") + .with_stderr_data(str![[r#" +[FRESH] foo v0.1.0 +[DIRTY] test v0.1.0 ([ROOT]/foo): name of dependency changed (foo => bar) +[COMPILING] test v0.1.0 ([ROOT]/foo) +[RUNNING] `rustc [..]` +error[E0463]: can't find crate for `foo` +... +"#]]) .run(); } @@ -274,18 +278,12 @@ fn can_run_doc_tests() { ) .build(); - foo.cargo("test -v") - .with_stderr_contains( - "\ + foo.cargo("test -v").with_stderr_data(str![[r#" +... [DOCTEST] foo -[RUNNING] `rustdoc [..]--test [..]src/lib.rs \ - [..] \ - --extern bar=[CWD]/target/debug/deps/libbar-[..].rlib \ - --extern baz=[CWD]/target/debug/deps/libbar-[..].rlib \ - [..]` -", - ) - .run(); +[RUNNING] `rustdoc [..]--test src/lib.rs [..] --extern bar=[ROOT]/foo/target/debug/deps/libbar-[HASH].rlib --extern baz=[ROOT]/foo/target/debug/deps/libbar-[HASH].rlib [..]` + +"#]]).run(); } #[cargo_test] @@ -373,14 +371,13 @@ fn features_not_working() { p.cargo("build -v") .with_status(101) - .with_stderr( - "\ -error: failed to parse manifest at `[..]` + .with_stderr_data(str![[r#" +[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml` Caused by: feature `default` includes `p1` which is neither a dependency nor another feature -", - ) + +"#]]) .run(); } From 2f37268dcde0d26273eb092a3218354f5fb199a0 Mon Sep 17 00:00:00 2001 From: eth3lbert Date: Sat, 22 Jun 2024 13:29:26 +0800 Subject: [PATCH 2/4] test: migrate replace to snapbox --- tests/testsuite/replace.rs | 439 ++++++++++++++++++------------------- 1 file changed, 214 insertions(+), 225 deletions(-) diff --git a/tests/testsuite/replace.rs b/tests/testsuite/replace.rs index d1efedcfbfa..7a388a0b71c 100644 --- a/tests/testsuite/replace.rs +++ b/tests/testsuite/replace.rs @@ -1,11 +1,9 @@ //! Tests for `[replace]` table source replacement. -#![allow(deprecated)] - use cargo_test_support::git; use cargo_test_support::paths; use cargo_test_support::registry::Package; -use cargo_test_support::{basic_manifest, project}; +use cargo_test_support::{basic_manifest, project, str}; #[cargo_test] fn override_simple() { @@ -43,16 +41,15 @@ fn override_simple() { .build(); p.cargo("check") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [UPDATING] `dummy-registry` index -[UPDATING] git repository `[..]` +[UPDATING] git repository `[ROOTURL]/override` [LOCKING] 3 packages to latest compatible versions -[CHECKING] bar v0.1.0 (file://[..]) -[CHECKING] foo v0.0.1 ([CWD]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -", - ) +[CHECKING] bar v0.1.0 ([ROOTURL]/override#[..]) +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -91,20 +88,16 @@ fn override_with_features() { ) .build(); - p.cargo("check") - .with_stderr( - "\ -[UPDATING] [..] index -[UPDATING] git repository `[..]` + p.cargo("check").with_stderr_data(str![[r#" +[UPDATING] `dummy-registry` index +[UPDATING] git repository `[ROOTURL]/override` [LOCKING] 3 packages to latest compatible versions -[WARNING] replacement for `bar` uses the features mechanism. default-features and features \ -will not take effect because the replacement dependency does not support this mechanism -[CHECKING] bar v0.1.0 (file://[..]) -[CHECKING] foo v0.0.1 ([CWD]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -", - ) - .run(); +[WARNING] replacement for `bar` uses the features mechanism. default-features and features will not take effect because the replacement dependency does not support this mechanism +[CHECKING] bar v0.1.0 ([ROOTURL]/override#[..]) +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]).run(); } #[cargo_test] @@ -142,20 +135,16 @@ fn override_with_setting_default_features() { ) .build(); - p.cargo("check") - .with_stderr( - "\ -[UPDATING] [..] index -[UPDATING] git repository `[..]` + p.cargo("check").with_stderr_data(str![[r#" +[UPDATING] `dummy-registry` index +[UPDATING] git repository `[ROOTURL]/override` [LOCKING] 3 packages to latest compatible versions -[WARNING] replacement for `bar` uses the features mechanism. default-features and features \ -will not take effect because the replacement dependency does not support this mechanism -[CHECKING] bar v0.1.0 (file://[..]) -[CHECKING] foo v0.0.1 ([CWD]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -", - ) - .run(); +[WARNING] replacement for `bar` uses the features mechanism. default-features and features will not take effect because the replacement dependency does not support this mechanism +[CHECKING] bar v0.1.0 ([ROOTURL]/override#[..]) +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]).run(); } #[cargo_test] @@ -180,17 +169,13 @@ fn missing_version() { .file("src/lib.rs", "") .build(); - p.cargo("check") - .with_status(101) - .with_stderr( - "\ -error: failed to parse manifest at `[..]` + p.cargo("check").with_status(101).with_stderr_data(str![[r#" +[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml` Caused by: - replacements must specify a version to replace, but `[..]bar` does not -", - ) - .run(); + replacements must specify a version to replace, but `https://github.com/rust-lang/crates.io-index#bar` does not + +"#]]).run(); } #[cargo_test] @@ -217,14 +202,13 @@ fn invalid_semver_version() { p.cargo("check") .with_status(101) - .with_stderr_contains( - "\ -error: failed to parse manifest at `[..]` + .with_stderr_data(str![[r#" +[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml` Caused by: replacements must specify a valid semver version to replace, but `bar:*` does not -", - ) +... +"#]]) .run(); } @@ -253,17 +237,13 @@ fn different_version() { .file("src/lib.rs", "") .build(); - p.cargo("check") - .with_status(101) - .with_stderr( - "\ -error: failed to parse manifest at `[..]` + p.cargo("check").with_status(101).with_stderr_data(str![[r#" +[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml` Caused by: - replacements cannot specify a version requirement, but found one for [..] -", - ) - .run(); + replacements cannot specify a version requirement, but found one for `https://github.com/rust-lang/crates.io-index#bar@0.1.0` + +"#]]).run(); } #[cargo_test] @@ -303,22 +283,26 @@ fn transitive() { .build(); p.cargo("check") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [UPDATING] `dummy-registry` index -[UPDATING] git repository `[..]` +[UPDATING] git repository `[ROOTURL]/override` [LOCKING] 4 packages to latest compatible versions [DOWNLOADING] crates ... -[DOWNLOADED] baz v0.2.0 (registry [..]) -[CHECKING] bar v0.1.0 (file://[..]) +[DOWNLOADED] baz v0.2.0 (registry `dummy-registry`) +[CHECKING] bar v0.1.0 ([ROOTURL]/override#[..]) [CHECKING] baz v0.2.0 -[CHECKING] foo v0.0.1 ([CWD]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -", - ) +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[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(); } #[cargo_test] @@ -357,19 +341,23 @@ fn persists_across_rebuilds() { .build(); p.cargo("check") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [UPDATING] `dummy-registry` index -[UPDATING] git repository `file://[..]` +[UPDATING] git repository `[ROOTURL]/override` [LOCKING] 3 packages to latest compatible versions -[CHECKING] bar v0.1.0 (file://[..]) -[CHECKING] foo v0.0.1 ([CWD]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -", - ) +[CHECKING] bar v0.1.0 ([ROOTURL]/override#[..]) +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[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(); } #[cargo_test] @@ -406,15 +394,14 @@ fn replace_registry_with_path() { .build(); p.cargo("check") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [UPDATING] `dummy-registry` index [LOCKING] 3 packages to latest compatible versions -[CHECKING] bar v0.1.0 ([ROOT][..]/bar) -[CHECKING] foo v0.0.1 ([CWD]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -", - ) +[CHECKING] bar v0.1.0 ([ROOT]/bar) +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -473,22 +460,21 @@ fn use_a_spec_to_select() { .build(); p.cargo("check") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [UPDATING] `dummy-registry` index -[UPDATING] git repository `[..]` +[UPDATING] git repository `[ROOTURL]/override` [LOCKING] 5 packages to latest compatible versions [ADDING] baz v0.1.1 (latest: v0.2.0) [DOWNLOADING] crates ... -[DOWNLOADED] [..] -[DOWNLOADED] [..] -[CHECKING] [..] -[CHECKING] [..] -[CHECKING] [..] -[CHECKING] foo v0.0.1 ([CWD]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -", - ) +[DOWNLOADED] baz v0.1.1 (registry `dummy-registry`) +[DOWNLOADED] bar v0.1.1 (registry `dummy-registry`) +[CHECKING] baz v0.2.0 ([ROOTURL]/override#[..]) +[CHECKING] baz v0.1.1 +[CHECKING] bar v0.1.1 +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -538,46 +524,53 @@ fn override_adds_some_deps() { .build(); p.cargo("check") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [UPDATING] `dummy-registry` index -[UPDATING] git repository `[..]` +[UPDATING] git repository `[ROOTURL]/override` [LOCKING] 4 packages to latest compatible versions [DOWNLOADING] crates ... -[DOWNLOADED] baz v0.1.1 (registry [..]) +[DOWNLOADED] baz v0.1.1 (registry `dummy-registry`) [CHECKING] baz v0.1.1 -[CHECKING] bar v0.1.0 ([..]) -[CHECKING] foo v0.0.1 ([CWD]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -", - ) +[CHECKING] bar v0.1.0 ([ROOTURL]/override#[..]) +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[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(); Package::new("baz", "0.1.2").publish(); p.cargo("update") .arg(&format!("{}#bar", foo.url())) - .with_stderr( - "\ -[UPDATING] git repository `file://[..]` + .with_stderr_data(str![[r#" +[UPDATING] git repository `[ROOTURL]/override` [UPDATING] `dummy-registry` index [LOCKING] 0 packages to latest compatible versions [NOTE] pass `--verbose` to see 1 unchanged dependencies behind latest -", - ) + +"#]]) .run(); p.cargo("update https://github.com/rust-lang/crates.io-index#bar") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [UPDATING] `dummy-registry` index [LOCKING] 0 packages to latest compatible versions [NOTE] pass `--verbose` to see 1 unchanged dependencies behind latest -", - ) + +"#]]) .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(); } #[cargo_test] @@ -630,8 +623,18 @@ fn locked_means_locked_yes_no_seriously_i_mean_locked() { p.cargo("check").run(); - p.cargo("check").with_stderr("[FINISHED] [..]").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") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) + .run(); } #[cargo_test] @@ -668,18 +671,17 @@ fn override_wrong_name() { p.cargo("check") .with_status(101) - .with_stderr( - "\ -[UPDATING] [..] index -[UPDATING] git repository [..] -[ERROR] failed to get `baz` as a dependency of package `foo v0.0.1 ([..])` + .with_stderr_data(str![[r#" +[UPDATING] `dummy-registry` index +[UPDATING] git repository `[ROOTURL]/override` +[ERROR] failed to get `baz` as a dependency of package `foo v0.0.1 ([ROOT]/foo)` Caused by: - no matching package for override `[..]baz@0.1.0` found - location searched: file://[..] + no matching package for override `https://github.com/rust-lang/crates.io-index#baz@0.1.0` found + location searched: [ROOTURL]/override version required: =0.1.0 -", - ) + +"#]]) .run(); } @@ -716,22 +718,21 @@ fn override_with_nothing() { p.cargo("check") .with_status(101) - .with_stderr( - "\ -[UPDATING] [..] index -[UPDATING] git repository [..] -[ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([..])` + .with_stderr_data(str![[r#" +[UPDATING] `dummy-registry` index +[UPDATING] git repository `[ROOTURL]/override` +[ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([ROOT]/foo)` Caused by: failed to load source for dependency `bar` Caused by: - Unable to update file://[..] + Unable to update [ROOTURL]/override Caused by: - Could not find Cargo.toml in `[..]` -", - ) + Could not find Cargo.toml in `[ROOT]/home/.cargo/git/checkouts/override-[HASH]/[..]` + +"#]]) .run(); } @@ -754,17 +755,13 @@ fn override_wrong_version() { .file("src/lib.rs", "") .build(); - p.cargo("check") - .with_status(101) - .with_stderr( - "\ -error: failed to parse manifest at `[..]` + p.cargo("check").with_status(101).with_stderr_data(str![[r#" +[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml` Caused by: - replacements cannot specify a version requirement, but found one for `[..]bar@0.1.0` -", - ) - .run(); + replacements cannot specify a version requirement, but found one for `https://github.com/rust-lang/crates.io-index#bar@0.1.0` + +"#]]).run(); } #[cargo_test] @@ -804,21 +801,20 @@ fn multiple_specs() { p.cargo("check") .with_status(101) - .with_stderr( - "\ -[UPDATING] [..] index -[UPDATING] git repository [..] -[ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([..])` + .with_stderr_data(str![[r#" +[UPDATING] `dummy-registry` index +[UPDATING] git repository `[ROOTURL]/override` +[ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([ROOT]/foo)` Caused by: overlapping replacement specifications found: - * [..] - * [..] + * https://github.com/rust-lang/crates.io-index#bar@0.1.0 + * https://github.com/rust-lang/crates.io-index#bar@0.1.0 both specifications match: bar v0.1.0 -", - ) + +"#]]) .run(); } @@ -856,14 +852,16 @@ fn test_override_dep() { p.cargo("test -p bar") .with_status(101) - .with_stderr_contains( - "\ -error: There are multiple `bar` packages in your project, and the [..] -Please re-run this command with [..] - [..]#bar@0.1.0 - [..]#bar@0.1.0 -", - ) + .with_stderr_data(str![[r#" +[UPDATING] `dummy-registry` index +[UPDATING] git repository `[ROOTURL]/override` +[LOCKING] 3 packages to latest compatible versions +[ERROR] There are multiple `bar` packages in your project, and the specification `bar` is ambiguous. +Please re-run this command with one of the following specifications: + registry+https://github.com/rust-lang/crates.io-index#bar@0.1.0 + git+[ROOTURL]/override#bar@0.1.0 + +"#]]) .run(); } @@ -901,13 +899,12 @@ fn update() { p.cargo("generate-lockfile").run(); p.cargo("update") - .with_stderr( - "\ -[UPDATING] `[..]` index -[UPDATING] git repository `[..]` + .with_stderr_data(str![[r#" +[UPDATING] `dummy-registry` index +[UPDATING] git repository `[ROOTURL]/override` [LOCKING] 0 packages to latest compatible versions -", - ) + +"#]]) .run(); } @@ -1122,13 +1119,12 @@ fn overriding_nonexistent_no_spurious() { p.cargo("check").run(); p.cargo("check") - .with_stderr( - "\ -[WARNING] package replacement is not used: [..]baz@0.1.0 -[FINISHED] [..] -", - ) - .with_stdout("") + .with_stderr_data(str![[r#" +[WARNING] package replacement is not used: https://github.com/rust-lang/crates.io-index#baz@0.1.0 +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) + .with_stdout_data("") .run(); } @@ -1172,25 +1168,25 @@ fn no_warnings_when_replace_is_used_in_another_workspace_member() { p.cargo("check") .cwd("first_crate") - .with_stdout("") - .with_stderr( - "\ -[UPDATING] `[..]` index + .with_stdout_data("") + .with_stderr_data(str![[r#" +[UPDATING] `dummy-registry` index [LOCKING] 4 packages to latest compatible versions -[CHECKING] bar v0.1.0 ([..]) -[CHECKING] first_crate v0.1.0 ([..]) -[FINISHED] [..]", - ) +[CHECKING] bar v0.1.0 ([ROOT]/foo/local_bar) +[CHECKING] first_crate v0.1.0 ([ROOT]/foo/first_crate) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); p.cargo("check") .cwd("second_crate") - .with_stdout("") - .with_stderr( - "\ -[CHECKING] second_crate v0.1.0 ([..]) -[FINISHED] [..]", - ) + .with_stdout_data("") + .with_stderr_data(str![[r#" +[CHECKING] second_crate v0.1.0 ([ROOT]/foo/second_crate) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -1346,7 +1342,14 @@ fn override_plus_dep() { p.cargo("check") .with_status(101) - .with_stderr_contains("error: cyclic package dependency: [..]") + .with_stderr_data(str![[r#" +[UPDATING] `dummy-registry` index +[ERROR] cyclic package dependency: package `bar v0.1.0 ([ROOT]/foo/bar)` depends on itself. Cycle: +package `bar v0.1.0 ([ROOT]/foo/bar)` + ... which satisfies dependency `bar = "^0.1"` of package `foo v0.0.1 ([ROOT]/foo)` + ... which satisfies path dependency `foo` of package `bar v0.1.0 ([ROOT]/foo/bar)` + +"#]]) .run(); } @@ -1385,20 +1388,16 @@ fn override_generic_matching_other_versions() { ) .build(); - p.cargo("check") - .with_stderr( - "\ + p.cargo("check").with_stderr_data(str![[r#" [UPDATING] `dummy-registry` index -[UPDATING] git repository `[..]` -[ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([..]/foo)` +[UPDATING] git repository `[ROOTURL]/override` +[ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([ROOT]/foo)` Caused by: replacement specification `https://github.com/rust-lang/crates.io-index#bar@0.1.0` matched 0.1.0+a and tried to override it with 0.1.0 avoid matching unrelated packages by being more specific -", - ) - .with_status(101) - .run(); + +"#]]).with_status(101).run(); } #[cargo_test] @@ -1436,28 +1435,19 @@ fn override_respects_spec_metadata() { ) .build(); - p.cargo("check") - .with_stderr( - "\ + p.cargo("check").with_stderr_data(str![[r#" [UPDATING] `dummy-registry` index [LOCKING] 2 packages to latest compatible versions [WARNING] package replacement is not used: https://github.com/rust-lang/crates.io-index#bar@0.1.0+notTheBuild [DOWNLOADING] crates ... [DOWNLOADED] bar v0.1.0+a (registry `dummy-registry`) [CHECKING] bar v0.1.0+a -[CHECKING] foo v0.0.1 ([..]/foo) -[..] -[..] -[..] -[..] -[..] -[..] -[..] -error: could not compile `foo` (lib) due to 1 previous error -", - ) - .with_status(101) - .run(); +[CHECKING] foo v0.0.1 ([ROOT]/foo) +error[E0425]: cannot find function `bar` in crate `bar` +... +[ERROR] could not compile `foo` (lib) due to 1 previous error + +"#]]).with_status(101).run(); } #[cargo_test] @@ -1496,15 +1486,14 @@ fn override_spec_metadata_is_optional() { .build(); p.cargo("check") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [UPDATING] `dummy-registry` index -[UPDATING] git repository `[..]` +[UPDATING] git repository `[ROOTURL]/override` [LOCKING] 3 packages to latest compatible versions -[CHECKING] bar v0.1.0+a (file://[..]) -[CHECKING] foo v0.0.1 ([CWD]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -", - ) +[CHECKING] bar v0.1.0+a ([ROOTURL]/override#[..]) +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } From 2a6869bbc11bc757d3b1e69c226bab7337866cb5 Mon Sep 17 00:00:00 2001 From: eth3lbert Date: Sat, 22 Jun 2024 15:32:33 +0800 Subject: [PATCH 3/4] test: migrate required_features to snapbox --- tests/testsuite/required_features.rs | 758 ++++++++++++++++----------- 1 file changed, 451 insertions(+), 307 deletions(-) diff --git a/tests/testsuite/required_features.rs b/tests/testsuite/required_features.rs index 5c53c79d4ee..787c3e1f117 100644 --- a/tests/testsuite/required_features.rs +++ b/tests/testsuite/required_features.rs @@ -1,13 +1,12 @@ //! Tests for targets with `required-features`. -#![allow(deprecated)] - use cargo_test_support::install::{ assert_has_installed_exe, assert_has_not_installed_exe, cargo_home, }; use cargo_test_support::is_nightly; use cargo_test_support::paths::CargoPathExt; use cargo_test_support::project; +use cargo_test_support::str; #[cargo_test] fn build_bin_default_features() { @@ -56,12 +55,11 @@ fn build_bin_default_features() { p.cargo("build --bin=foo --no-default-features") .with_status(101) - .with_stderr( - "\ -error: target `foo` in package `foo` requires the features: `a` -Consider enabling them by passing, e.g., `--features=\"a\"` -", - ) + .with_stderr_data(str![[r#" +[ERROR] target `foo` in package `foo` requires the features: `a` +Consider enabling them by passing, e.g., `--features="a"` + +"#]]) .run(); } @@ -167,12 +165,11 @@ fn build_example_default_features() { p.cargo("build --example=foo --no-default-features") .with_status(101) - .with_stderr( - "\ -error: target `foo` in package `foo` requires the features: `a` -Consider enabling them by passing, e.g., `--features=\"a\"` -", - ) + .with_stderr_data(str![[r#" +[ERROR] target `foo` in package `foo` requires the features: `a` +Consider enabling them by passing, e.g., `--features="a"` + +"#]]) .run(); } @@ -236,12 +233,11 @@ fn build_example_multiple_required_features() { p.cargo("build --example=foo_1") .with_status(101) - .with_stderr( - "\ -error: target `foo_1` in package `foo` requires the features: `b`, `c` -Consider enabling them by passing, e.g., `--features=\"b c\"` -", - ) + .with_stderr_data(str![[r#" +[ERROR] target `foo_1` in package `foo` requires the features: `b`, `c` +Consider enabling them by passing, e.g., `--features="b c"` + +"#]]) .run(); p.cargo("build --example=foo_2").run(); @@ -256,21 +252,19 @@ Consider enabling them by passing, e.g., `--features=\"b c\"` p.cargo("build --example=foo_1 --no-default-features") .with_status(101) - .with_stderr( - "\ -error: target `foo_1` in package `foo` requires the features: `b`, `c` -Consider enabling them by passing, e.g., `--features=\"b c\"` -", - ) + .with_stderr_data(str![[r#" +[ERROR] target `foo_1` in package `foo` requires the features: `b`, `c` +Consider enabling them by passing, e.g., `--features="b c"` + +"#]]) .run(); p.cargo("build --example=foo_2 --no-default-features") .with_status(101) - .with_stderr( - "\ -error: target `foo_2` in package `foo` requires the features: `a` -Consider enabling them by passing, e.g., `--features=\"a\"` -", - ) + .with_stderr_data(str![[r#" +[ERROR] target `foo_2` in package `foo` requires the features: `a` +Consider enabling them by passing, e.g., `--features="a"` + +"#]]) .run(); } @@ -299,37 +293,55 @@ fn test_default_features() { .build(); p.cargo("test") - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [..] -[RUNNING] [..] (target/debug/deps/foo-[..][EXE])", - ) - .with_stdout_contains("test test ... ok") + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] tests/foo.rs (target/debug/deps/foo-[HASH][EXE]) + +"#]]) + .with_stdout_data(str![[r#" + +running 1 test +test test ... ok + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s + + +"#]]) .run(); p.cargo("test --no-default-features") - .with_stderr("[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [..]") - .with_stdout("") + .with_stderr_data(str![[r#" +[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) + .with_stdout_data("") .run(); p.cargo("test --test=foo") - .with_stderr( - "\ -[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [..] -[RUNNING] [..] (target/debug/deps/foo-[..][EXE])", - ) - .with_stdout_contains("test test ... ok") + .with_stderr_data(str![[r#" +[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] tests/foo.rs (target/debug/deps/foo-[HASH][EXE]) + +"#]]) + .with_stdout_data(str![[r#" + +running 1 test +test test ... ok + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s + + +"#]]) .run(); p.cargo("test --test=foo --no-default-features") .with_status(101) - .with_stderr( - "\ -error: target `foo` in package `foo` requires the features: `a` -Consider enabling them by passing, e.g., `--features=\"a\"` -", - ) + .with_stderr_data(str![[r#" +[ERROR] target `foo` in package `foo` requires the features: `a` +Consider enabling them by passing, e.g., `--features="a"` + +"#]]) .run(); } @@ -357,13 +369,21 @@ fn test_arg_features() { .build(); p.cargo("test --features a") - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [..] -[RUNNING] [..] (target/debug/deps/foo-[..][EXE])", - ) - .with_stdout_contains("test test ... ok") + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] tests/foo.rs (target/debug/deps/foo-[HASH][EXE]) + +"#]]) + .with_stdout_data(str![[r#" + +running 1 test +test test ... ok + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s + + +"#]]) .run(); } @@ -399,29 +419,54 @@ fn test_multiple_required_features() { .build(); p.cargo("test") - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [..] -[RUNNING] [..] (target/debug/deps/foo_2-[..][EXE])", - ) - .with_stdout_contains("test test ... ok") + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] tests/foo_2.rs (target/debug/deps/foo_2-[HASH][EXE]) + +"#]]) + .with_stdout_data(str![[r#" + +running 1 test +test test ... ok + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s + + +"#]]) .run(); p.cargo("test --features c") - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [..] -[RUNNING] [..] (target/debug/deps/foo_1-[..][EXE]) -[RUNNING] [..] (target/debug/deps/foo_2-[..][EXE])", - ) - .with_stdout_contains_n("test test ... ok", 2) + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] tests/foo_1.rs (target/debug/deps/foo_1-[HASH][EXE]) +[RUNNING] tests/foo_2.rs (target/debug/deps/foo_2-[HASH][EXE]) + +"#]]) + .with_stdout_data(str![[r#" + +running 1 test +test test ... ok + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s + + +running 1 test +test test ... ok + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s + + +"#]]) .run(); p.cargo("test --no-default-features") - .with_stderr("[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [..]") - .with_stdout("") + .with_stderr_data(str![[r#" +[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) + .with_stdout_data("") .run(); } @@ -460,37 +505,55 @@ fn bench_default_features() { .build(); p.cargo("bench") - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] `bench` profile [optimized] target(s) in [..] -[RUNNING] [..] (target/release/deps/foo-[..][EXE])", - ) - .with_stdout_contains("test bench ... bench: [..]") + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `bench` profile [optimized] target(s) in [ELAPSED]s +[RUNNING] benches/foo.rs (target/release/deps/foo-[HASH][EXE]) + +"#]]) + .with_stdout_data(str![[r#" + +running 1 test +test bench ... bench: [AVG_ELAPSED] ns/iter (+/- [JITTER]) + +test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured; 0 filtered out; finished in [ELAPSED]s + + +"#]]) .run(); p.cargo("bench --no-default-features") - .with_stderr("[FINISHED] `bench` profile [optimized] target(s) in [..]".to_string()) - .with_stdout("") + .with_stderr_data(str![[r#" +[FINISHED] `bench` profile [optimized] target(s) in [ELAPSED]s + +"#]]) + .with_stdout_data("") .run(); p.cargo("bench --bench=foo") - .with_stderr( - "\ -[FINISHED] `bench` profile [optimized] target(s) in [..] -[RUNNING] [..] (target/release/deps/foo-[..][EXE])", - ) - .with_stdout_contains("test bench ... bench: [..]") + .with_stderr_data(str![[r#" +[FINISHED] `bench` profile [optimized] target(s) in [ELAPSED]s +[RUNNING] benches/foo.rs (target/release/deps/foo-[HASH][EXE]) + +"#]]) + .with_stdout_data(str![[r#" + +running 1 test +test bench ... bench: [AVG_ELAPSED] ns/iter (+/- [JITTER]) + +test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured; 0 filtered out; finished in [ELAPSED]s + + +"#]]) .run(); p.cargo("bench --bench=foo --no-default-features") .with_status(101) - .with_stderr( - "\ -error: target `foo` in package `foo` requires the features: `a` -Consider enabling them by passing, e.g., `--features=\"a\"` -", - ) + .with_stderr_data(str![[r#" +[ERROR] target `foo` in package `foo` requires the features: `a` +Consider enabling them by passing, e.g., `--features="a"` + +"#]]) .run(); } @@ -528,13 +591,21 @@ fn bench_arg_features() { .build(); p.cargo("bench --features a") - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] `bench` profile [optimized] target(s) in [..] -[RUNNING] [..] (target/release/deps/foo-[..][EXE])", - ) - .with_stdout_contains("test bench ... bench: [..]") + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `bench` profile [optimized] target(s) in [ELAPSED]s +[RUNNING] benches/foo.rs (target/release/deps/foo-[HASH][EXE]) + +"#]]) + .with_stdout_data(str![[r#" + +running 1 test +test bench ... bench: [AVG_ELAPSED] ns/iter (+/- [JITTER]) + +test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured; 0 filtered out; finished in [ELAPSED]s + + +"#]]) .run(); } @@ -590,29 +661,54 @@ fn bench_multiple_required_features() { .build(); p.cargo("bench") - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] `bench` profile [optimized] target(s) in [..] -[RUNNING] [..] (target/release/deps/foo_2-[..][EXE])", - ) - .with_stdout_contains("test bench ... bench: [..]") + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `bench` profile [optimized] target(s) in [ELAPSED]s +[RUNNING] benches/foo_2.rs (target/release/deps/foo_2-[HASH][EXE]) + +"#]]) + .with_stdout_data(str![[r#" + +running 1 test +test bench ... bench: [AVG_ELAPSED] ns/iter (+/- [JITTER]) + +test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured; 0 filtered out; finished in [ELAPSED]s + + +"#]]) .run(); p.cargo("bench --features c") - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] `bench` profile [optimized] target(s) in [..] -[RUNNING] [..] (target/release/deps/foo_1-[..][EXE]) -[RUNNING] [..] (target/release/deps/foo_2-[..][EXE])", - ) - .with_stdout_contains_n("test bench ... bench: [..]", 2) + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `bench` profile [optimized] target(s) in [ELAPSED]s +[RUNNING] benches/foo_1.rs (target/release/deps/foo_1-[HASH][EXE]) +[RUNNING] benches/foo_2.rs (target/release/deps/foo_2-[HASH][EXE]) + +"#]]) + .with_stdout_data(str![[r#" + +running 1 test +test bench ... bench: [AVG_ELAPSED] ns/iter (+/- [JITTER]) + +test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured; 0 filtered out; finished in [ELAPSED]s + + +running 1 test +test bench ... bench: [AVG_ELAPSED] ns/iter (+/- [JITTER]) + +test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured; 0 filtered out; finished in [ELAPSED]s + + +"#]]) .run(); p.cargo("bench --no-default-features") - .with_stderr("[FINISHED] `bench` profile [optimized] target(s) in [..]") - .with_stdout("") + .with_stderr_data(str![[r#" +[FINISHED] `bench` profile [optimized] target(s) in [ELAPSED]s + +"#]]) + .with_stdout_data("") .run(); } @@ -650,16 +746,15 @@ fn install_default_features() { p.cargo("uninstall foo").run(); p.cargo("install --path . --no-default-features") - .with_stderr( - "\ -[INSTALLING] foo v0.0.1 ([..]) -[FINISHED] `release` profile [optimized] target(s) in [..] + .with_stderr_data(str![[r#" +[INSTALLING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s [WARNING] none of the package's binaries are available for install using the selected features - bin \"foo\" requires the features: `a` - example \"foo\" requires the features: `a` -Consider enabling some of the needed features by passing, e.g., `--features=\"a\"` -", - ) + bin "foo" requires the features: `a` + example "foo" requires the features: `a` +Consider enabling some of the needed features by passing, e.g., `--features="a"` + +"#]]) .run(); assert_has_not_installed_exe(cargo_home(), "foo"); @@ -669,19 +764,16 @@ Consider enabling some of the needed features by passing, e.g., `--features=\"a\ p.cargo("install --path . --bin=foo --no-default-features") .with_status(101) - .with_stderr( - "\ -[INSTALLING] foo v0.0.1 ([..]) -[ERROR] failed to compile `foo v0.0.1 ([..])`, intermediate artifacts can be found at \ - `[..]target`. -To reuse those artifacts with a future compilation, set the environment \ -variable `CARGO_TARGET_DIR` to that path. + .with_stderr_data(str![[r#" +[INSTALLING] foo v0.0.1 ([ROOT]/foo) +[ERROR] failed to compile `foo v0.0.1 ([ROOT]/foo)`, intermediate artifacts can be found at `[ROOT]/foo/target`. +To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path. Caused by: target `foo` in package `foo` requires the features: `a` - Consider enabling them by passing, e.g., `--features=\"a\"` -", - ) + Consider enabling them by passing, e.g., `--features="a"` + +"#]]) .run(); assert_has_not_installed_exe(cargo_home(), "foo"); @@ -691,18 +783,16 @@ Caused by: p.cargo("install --path . --example=foo --no-default-features") .with_status(101) - .with_stderr( - "\ -[INSTALLING] foo v0.0.1 ([..]) -[ERROR] failed to compile `foo v0.0.1 ([..])`, intermediate artifacts can be found at \ - `[..]target`.\nTo reuse those artifacts with a future compilation, set the environment \ - variable `CARGO_TARGET_DIR` to that path. + .with_stderr_data(str![[r#" +[INSTALLING] foo v0.0.1 ([ROOT]/foo) +[ERROR] failed to compile `foo v0.0.1 ([ROOT]/foo)`, intermediate artifacts can be found at `[ROOT]/foo/target`. +To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path. Caused by: target `foo` in package `foo` requires the features: `a` - Consider enabling them by passing, e.g., `--features=\"a\"` -", - ) + Consider enabling them by passing, e.g., `--features="a"` + +"#]]) .run(); assert_has_not_installed_exe(cargo_home(), "foo"); } @@ -810,63 +900,59 @@ fn install_multiple_required_features() { p.cargo("uninstall foo").run(); p.cargo("install --path . --no-default-features") - .with_stderr( - "\ -[INSTALLING] foo v0.0.1 ([..]) -[FINISHED] `release` profile [optimized] target(s) in [..] + .with_stderr_data(str![[r#" +[INSTALLING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s [WARNING] none of the package's binaries are available for install using the selected features - bin \"foo_1\" requires the features: `b`, `c` - bin \"foo_2\" requires the features: `a` - example \"foo_3\" requires the features: `b`, `c` - example \"foo_4\" requires the features: `a` -Consider enabling some of the needed features by passing, e.g., `--features=\"b c\"` -", - ) + bin "foo_1" requires the features: `b`, `c` + bin "foo_2" requires the features: `a` + example "foo_3" requires the features: `b`, `c` + example "foo_4" requires the features: `a` +Consider enabling some of the needed features by passing, e.g., `--features="b c"` + +"#]]) .run(); p.cargo("install --path . --no-default-features --bins") - .with_stderr( - "\ -[INSTALLING] foo v0.0.1 ([..]) + .with_stderr_data(str![[r#" +[INSTALLING] foo v0.0.1 ([ROOT]/foo) [WARNING] target filter `bins` specified, but no targets matched; this is a no-op -[FINISHED] `release` profile [optimized] target(s) in [..] +[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s [WARNING] none of the package's binaries are available for install using the selected features - bin \"foo_1\" requires the features: `b`, `c` - bin \"foo_2\" requires the features: `a` - example \"foo_3\" requires the features: `b`, `c` - example \"foo_4\" requires the features: `a` -Consider enabling some of the needed features by passing, e.g., `--features=\"b c\"` -", - ) + bin "foo_1" requires the features: `b`, `c` + bin "foo_2" requires the features: `a` + example "foo_3" requires the features: `b`, `c` + example "foo_4" requires the features: `a` +Consider enabling some of the needed features by passing, e.g., `--features="b c"` + +"#]]) .run(); p.cargo("install --path . --no-default-features --examples") - .with_stderr( - "\ -[INSTALLING] foo v0.0.1 ([..]) + .with_stderr_data(str![[r#" +[INSTALLING] foo v0.0.1 ([ROOT]/foo) [WARNING] target filter `examples` specified, but no targets matched; this is a no-op -[FINISHED] `release` profile [optimized] target(s) in [..] +[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s [WARNING] none of the package's binaries are available for install using the selected features - bin \"foo_1\" requires the features: `b`, `c` - bin \"foo_2\" requires the features: `a` - example \"foo_3\" requires the features: `b`, `c` - example \"foo_4\" requires the features: `a` -Consider enabling some of the needed features by passing, e.g., `--features=\"b c\"` -", - ) + bin "foo_1" requires the features: `b`, `c` + bin "foo_2" requires the features: `a` + example "foo_3" requires the features: `b`, `c` + example "foo_4" requires the features: `a` +Consider enabling some of the needed features by passing, e.g., `--features="b c"` + +"#]]) .run(); p.cargo("install --path . --no-default-features --bins --examples") - .with_stderr( - "\ -[INSTALLING] foo v0.0.1 ([..]) + .with_stderr_data(str![[r#" +[INSTALLING] foo v0.0.1 ([ROOT]/foo) [WARNING] target filters `bins`, `examples` specified, but no targets matched; this is a no-op -[FINISHED] `release` profile [optimized] target(s) in [..] +[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s [WARNING] none of the package's binaries are available for install using the selected features - bin \"foo_1\" requires the features: `b`, `c` - bin \"foo_2\" requires the features: `a` - example \"foo_3\" requires the features: `b`, `c` - example \"foo_4\" requires the features: `a` -Consider enabling some of the needed features by passing, e.g., `--features=\"b c\"` -", - ) + bin "foo_1" requires the features: `b`, `c` + bin "foo_2" requires the features: `a` + example "foo_3" requires the features: `b`, `c` + example "foo_4" requires the features: `a` +Consider enabling some of the needed features by passing, e.g., `--features="b c"` + +"#]]) .run(); assert_has_not_installed_exe(cargo_home(), "foo_1"); assert_has_not_installed_exe(cargo_home(), "foo_2"); @@ -948,26 +1034,42 @@ fn dep_feature_in_toml() { // test p.cargo("test --test=foo") - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [..] -[RUNNING] [..] (target/debug/deps/foo-[..][EXE])", - ) - .with_stdout_contains("test test ... ok") + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] tests/foo.rs (target/debug/deps/foo-[HASH][EXE]) + +"#]]) + .with_stdout_data(str![[r#" + +running 1 test +test test ... ok + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s + + +"#]]) .run(); // bench if is_nightly() { p.cargo("bench --bench=foo") - .with_stderr( - "\ -[COMPILING] bar v0.0.1 ([CWD]/bar) -[COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] `bench` profile [optimized] target(s) in [..] -[RUNNING] [..] (target/release/deps/foo-[..][EXE])", - ) - .with_stdout_contains("test bench ... bench: [..]") + .with_stderr_data(str![[r#" +[COMPILING] bar v0.0.1 ([ROOT]/foo/bar) +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `bench` profile [optimized] target(s) in [ELAPSED]s +[RUNNING] benches/foo.rs (target/release/deps/foo-[HASH][EXE]) + +"#]]) + .with_stdout_data(str![[r#" + +running 1 test +test bench ... bench: [AVG_ELAPSED] ns/iter (+/- [JITTER]) + +test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured; 0 filtered out; finished in [ELAPSED]s + + +"#]]) .run(); } @@ -1051,23 +1153,22 @@ fn dep_feature_in_cmd_line() { // This is a no-op p.cargo("build") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [LOCKING] 2 packages to latest compatible versions -[FINISHED] `dev` profile [..]", - ) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); assert!(!p.bin("foo").is_file()); // bin p.cargo("build --bin=foo") .with_status(101) - .with_stderr( - "\ -error: target `foo` in package `foo` requires the features: `bar/a` -Consider enabling them by passing, e.g., `--features=\"bar/a\"` -", - ) + .with_stderr_data(str![[r#" +[ERROR] target `foo` in package `foo` requires the features: `bar/a` +Consider enabling them by passing, e.g., `--features="bar/a"` + +"#]]) .run(); p.cargo("build --bin=foo --features bar/a").run(); @@ -1076,12 +1177,11 @@ Consider enabling them by passing, e.g., `--features=\"bar/a\"` // example p.cargo("build --example=foo") .with_status(101) - .with_stderr( - "\ -error: target `foo` in package `foo` requires the features: `bar/a` -Consider enabling them by passing, e.g., `--features=\"bar/a\"` -", - ) + .with_stderr_data(str![[r#" +[ERROR] target `foo` in package `foo` requires the features: `bar/a` +Consider enabling them by passing, e.g., `--features="bar/a"` + +"#]]) .run(); p.cargo("build --example=foo --features bar/a").run(); @@ -1090,55 +1190,76 @@ Consider enabling them by passing, e.g., `--features=\"bar/a\"` // test // This is a no-op, since no tests are enabled p.cargo("test") - .with_stderr("[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [..]") - .with_stdout("") + .with_stderr_data(str![[r#" +[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) + .with_stdout_data("") .run(); // Delete the target directory so this can check if the main.rs gets built. p.build_dir().rm_rf(); p.cargo("test --test=foo --features bar/a") - .with_stderr( - "\ -[COMPILING] bar v0.0.1 ([CWD]/bar) -[COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [..] -[RUNNING] [..] (target/debug/deps/foo-[..][EXE])", - ) - .with_stdout_contains("test bin_is_built ... ok") + .with_stderr_data(str![[r#" +[COMPILING] bar v0.0.1 ([ROOT]/foo/bar) +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] tests/foo.rs (target/debug/deps/foo-[HASH][EXE]) + +"#]]) + .with_stdout_data(str![[r#" + +running 1 test +test bin_is_built ... ok + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s + + +"#]]) .run(); // bench if is_nightly() { p.cargo("bench") - .with_stderr("[FINISHED] `bench` profile [optimized] target(s) in [..]") - .with_stdout("") + .with_stderr_data(str![[r#" +[FINISHED] `bench` profile [optimized] target(s) in [ELAPSED]s + +"#]]) + .with_stdout_data("") .run(); p.cargo("bench --bench=foo --features bar/a") - .with_stderr( - "\ -[COMPILING] bar v0.0.1 ([CWD]/bar) -[COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] `bench` profile [optimized] target(s) in [..] -[RUNNING] [..] (target/release/deps/foo-[..][EXE])", - ) - .with_stdout_contains("test bench ... bench: [..]") + .with_stderr_data(str![[r#" +[COMPILING] bar v0.0.1 ([ROOT]/foo/bar) +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `bench` profile [optimized] target(s) in [ELAPSED]s +[RUNNING] benches/foo.rs (target/release/deps/foo-[HASH][EXE]) + +"#]]) + .with_stdout_data(str![[r#" + +running 1 test +test bench ... bench: [AVG_ELAPSED] ns/iter (+/- [JITTER]) + +test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured; 0 filtered out; finished in [ELAPSED]s + + +"#]]) .run(); } // install p.cargo("install --path .") - .with_stderr( - "\ -[INSTALLING] foo v0.0.1 ([..]) + .with_stderr_data(str![[r#" +[INSTALLING] foo v0.0.1 ([ROOT]/foo) [LOCKING] 2 packages to latest compatible versions -[FINISHED] `release` profile [optimized] target(s) in [..] +[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s [WARNING] none of the package's binaries are available for install using the selected features - bin \"foo\" requires the features: `bar/a` - example \"foo\" requires the features: `bar/a` -Consider enabling some of the needed features by passing, e.g., `--features=\"bar/a\"` -", - ) + bin "foo" requires the features: `bar/a` + example "foo" requires the features: `bar/a` +Consider enabling some of the needed features by passing, e.g., `--features="bar/a"` + +"#]]) .run(); assert_has_not_installed_exe(cargo_home(), "foo"); @@ -1174,42 +1295,56 @@ fn test_skips_compiling_bin_with_missing_required_features() { .build(); p.cargo("test") - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [..] -[RUNNING] [..] (target/debug/deps/foo-[..][EXE])", - ) - .with_stdout_contains("running 0 tests") + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] tests/foo.rs (target/debug/deps/foo-[HASH][EXE]) + +"#]]) + .with_stdout_data(str![[r#" + +running 0 tests + +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s + + +"#]]) .run(); p.cargo("test --features a -j 1") .with_status(101) - .with_stderr_contains( - "\ -[COMPILING] foo v0.0.1 ([CWD]) -error[E0463]: can't find crate for `bar`", - ) + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +error[E0463]: can't find crate for `bar` +... +"#]]) .run(); if is_nightly() { p.cargo("bench") - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] `bench` profile [optimized] target(s) in [..] -[RUNNING] [..] (target/release/deps/foo-[..][EXE])", - ) - .with_stdout_contains("running 0 tests") + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `bench` profile [optimized] target(s) in [ELAPSED]s +[RUNNING] benches/foo.rs (target/release/deps/foo-[HASH][EXE]) + +"#]]) + .with_stdout_data(str![[r#" + +running 0 tests + +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s + + +"#]]) .run(); p.cargo("bench --features a -j 1") .with_status(101) - .with_stderr_contains( - "\ -[COMPILING] foo v0.0.1 ([CWD]) -error[E0463]: can't find crate for `bar`", - ) + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +error[E0463]: can't find crate for `bar` +... +"#]]) .run(); } } @@ -1241,12 +1376,11 @@ fn run_default() { p.cargo("run") .with_status(101) - .with_stderr( - "\ -error: target `foo` in package `foo` requires the features: `a` -Consider enabling them by passing, e.g., `--features=\"a\"` -", - ) + .with_stderr_data(str![[r#" +[ERROR] target `foo` in package `foo` requires the features: `a` +Consider enabling them by passing, e.g., `--features="a"` + +"#]]) .run(); p.cargo("run --features a").run(); @@ -1293,11 +1427,11 @@ fn run_default_multiple_required_features() { p.cargo("run") .with_status(101) - .with_stderr( - "\ -error: `cargo run` could not determine which binary to run[..] -available binaries: foo1, foo2, foo3", - ) + .with_stderr_data(str![[r#" +[ERROR] `cargo run` could not determine which binary to run. Use the `--bin` option to specify a binary, or the `default-run` manifest key. +available binaries: foo1, foo2, foo3 + +"#]]) .run(); } @@ -1377,21 +1511,29 @@ fn renamed_required_features() { p.cargo("run") .with_status(101) - .with_stderr( - "\ + .with_stderr_data(str![[r#" [LOCKING] 3 packages to latest compatible versions [ERROR] target `x` in package `foo` requires the features: `a1/f1` -Consider enabling them by passing, e.g., `--features=\"a1/f1\"` -", - ) +Consider enabling them by passing, e.g., `--features="a1/f1"` + +"#]]) .run(); p.cargo("build --features a1/f1").run(); - p.rename_run("x", "x_with_f1").with_stdout("a1 f1").run(); + p.rename_run("x", "x_with_f1") + .with_stdout_data(str![[r#" +a1 f1 + +"#]]) + .run(); p.cargo("build --features a1/f1,a2/f2").run(); p.rename_run("x", "x_with_f1_f2") - .with_stdout("a1 f1\na2 f2") + .with_stdout_data(str![[r#" +a1 f1 +a2 f2 + +"#]]) .run(); } @@ -1471,17 +1613,19 @@ fn truncated_install_warning_message() { .file("examples/example1.rs", "fn main() {}") .build(); - p.cargo("install --path .").with_stderr("\ -[INSTALLING] foo v0.1.0 ([..]) -[FINISHED] `release` profile [optimized] target(s) in [..] + p.cargo("install --path .").with_stderr_data(str![[r#" +[INSTALLING] foo v0.1.0 ([ROOT]/foo) +[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s [WARNING] none of the package's binaries are available for install using the selected features - bin \"foo1\" requires the features: `feature1`, `feature2`, `feature3` - bin \"foo10\" requires the features: `feature1`, `feature2`, `feature3`, `feature4`, `feature5` - bin \"foo2\" requires the features: `feature2` - bin \"foo3\" requires the features: `feature3` - bin \"foo4\" requires the features: `feature4`, `feature1` - bin \"foo5\" requires the features: `feature1`, `feature2`, `feature3`, `feature4`, `feature5` - bin \"foo6\" requires the features: `feature1`, `feature2`, `feature3`, `feature4`, `feature5` + bin "foo1" requires the features: `feature1`, `feature2`, `feature3` + bin "foo10" requires the features: `feature1`, `feature2`, `feature3`, `feature4`, `feature5` + bin "foo2" requires the features: `feature2` + bin "foo3" requires the features: `feature3` + bin "foo4" requires the features: `feature4`, `feature1` + bin "foo5" requires the features: `feature1`, `feature2`, `feature3`, `feature4`, `feature5` + bin "foo6" requires the features: `feature1`, `feature2`, `feature3`, `feature4`, `feature5` 4 more targets also requires features not enabled. See them in the Cargo.toml file. -Consider enabling some of the needed features by passing, e.g., `--features=\"feature1 feature2 feature3\"`").run(); +Consider enabling some of the needed features by passing, e.g., `--features="feature1 feature2 feature3"` + +"#]]).run(); } From 913b12b8d4cd4733436b30fceae702ee35118610 Mon Sep 17 00:00:00 2001 From: eth3lbert Date: Sat, 22 Jun 2024 18:44:28 +0800 Subject: [PATCH 4/4] test: migrate run to snapbox --- tests/testsuite/run.rs | 706 +++++++++++++++++++++++------------------ 1 file changed, 403 insertions(+), 303 deletions(-) diff --git a/tests/testsuite/run.rs b/tests/testsuite/run.rs index f7ee65f013d..de981df4704 100644 --- a/tests/testsuite/run.rs +++ b/tests/testsuite/run.rs @@ -1,9 +1,7 @@ //! Tests for the `cargo run` command. -#![allow(deprecated)] - use cargo_test_support::{ - basic_bin_manifest, basic_lib_manifest, basic_manifest, project, Project, + basic_bin_manifest, basic_lib_manifest, basic_manifest, project, str, Project, }; use cargo_util::paths::dylib_path_envvar; @@ -14,13 +12,16 @@ fn simple() { .build(); p.cargo("run") - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -[RUNNING] `target/debug/foo[EXE]`", - ) - .with_stdout("hello") + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] `target/debug/foo[EXE]` + +"#]]) + .with_stdout_data(str![[r#" +hello + +"#]]) .run(); assert!(p.bin("foo").is_file()); } @@ -31,11 +32,20 @@ fn quiet_arg() { .file("src/main.rs", r#"fn main() { println!("hello"); }"#) .build(); - p.cargo("run -q").with_stderr("").with_stdout("hello").run(); + p.cargo("run -q") + .with_stderr_data("") + .with_stdout_data(str![[r#" +hello + +"#]]) + .run(); p.cargo("run --quiet") - .with_stderr("") - .with_stdout("hello") + .with_stderr_data("") + .with_stdout_data(str![[r#" +hello + +"#]]) .run(); } @@ -46,32 +56,30 @@ fn unsupported_silent_arg() { .build(); p.cargo("run -s") - .with_stderr( - "\ -error: unexpected argument '--silent' found + .with_stderr_data(str![[r#" +[ERROR] unexpected argument '--silent' found tip: a similar argument exists: '--quiet' Usage: cargo[EXE] run [OPTIONS] [ARGS]... For more information, try '--help'. -", - ) + +"#]]) .with_status(1) .run(); p.cargo("run --silent") - .with_stderr( - "\ -error: unexpected argument '--silent' found + .with_stderr_data(str![[r#" +[ERROR] unexpected argument '--silent' found tip: a similar argument exists: '--quiet' Usage: cargo[EXE] run [OPTIONS] [ARGS]... For more information, try '--help'. -", - ) + +"#]]) .with_status(1) .run(); } @@ -84,7 +92,10 @@ fn quiet_arg_and_verbose_arg() { p.cargo("run -q -v") .with_status(101) - .with_stderr("[ERROR] cannot set both --verbose and --quiet") + .with_stderr_data(str![[r#" +[ERROR] cannot set both --verbose and --quiet + +"#]]) .run(); } @@ -101,7 +112,13 @@ fn quiet_arg_and_verbose_config() { .file("src/main.rs", r#"fn main() { println!("hello"); }"#) .build(); - p.cargo("run -q").with_stderr("").with_stdout("hello").run(); + p.cargo("run -q") + .with_stderr_data("") + .with_stdout_data(str![[r#" +hello + +"#]]) + .run(); } #[cargo_test] @@ -118,14 +135,17 @@ fn verbose_arg_and_quiet_config() { .build(); p.cargo("run -v") - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([CWD]) -[RUNNING] `rustc [..] -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -[RUNNING] `target/debug/foo[EXE]`", - ) - .with_stdout("hello") + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[RUNNING] `rustc [..]` +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] `target/debug/foo[EXE]` + +"#]]) + .with_stdout_data(str![[r#" +hello + +"#]]) .run(); } @@ -142,7 +162,13 @@ fn quiet_config_alone() { .file("src/main.rs", r#"fn main() { println!("hello"); }"#) .build(); - p.cargo("run").with_stderr("").with_stdout("hello").run(); + p.cargo("run") + .with_stderr_data("") + .with_stdout_data(str![[r#" +hello + +"#]]) + .run(); } #[cargo_test] @@ -159,14 +185,17 @@ fn verbose_config_alone() { .build(); p.cargo("run") - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([CWD]) -[RUNNING] `rustc [..] -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -[RUNNING] `target/debug/foo[EXE]`", - ) - .with_stdout("hello") + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[RUNNING] `rustc [..]` +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] `target/debug/foo[EXE]` + +"#]]) + .with_stdout_data(str![[r#" +hello + +"#]]) .run(); } @@ -186,7 +215,10 @@ fn quiet_config_and_verbose_config() { p.cargo("run") .with_status(101) - .with_stderr("[ERROR] cannot set both `term.verbose` and `term.quiet`") + .with_stderr_data(str![[r#" +[ERROR] cannot set both `term.verbose` and `term.quiet` + +"#]]) .run(); } @@ -239,19 +271,26 @@ fn exit_code() { .file("src/main.rs", "fn main() { std::process::exit(2); }") .build(); - let mut output = String::from( - "\ -[COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -[RUNNING] `target[..]` -", - ); - if !cfg!(unix) { - output.push_str( - "[ERROR] process didn't exit successfully: `target[..]foo[..]` (exit [..]: 2)", - ); - } - p.cargo("run").with_status(2).with_stderr(output).run(); + let expected = if !cfg!(unix) { + str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] `target/debug/foo[EXE]` +[ERROR] process didn't exit successfully: `target/debug/foo[EXE]` ([EXIT_STATUS]: 2) + +"#]] + } else { + str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] `target/debug/foo` + +"#]] + }; + p.cargo("run") + .with_status(2) + .with_stderr_data(expected) + .run(); } #[cargo_test] @@ -260,21 +299,29 @@ fn exit_code_verbose() { .file("src/main.rs", "fn main() { std::process::exit(2); }") .build(); - let mut output = String::from( - "\ -[COMPILING] foo v0.0.1 ([CWD]) + let expected = if !cfg!(unix) { + str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) [RUNNING] `rustc [..]` -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -[RUNNING] `target[..]` -", - ); - if !cfg!(unix) { - output.push_str( - "[ERROR] process didn't exit successfully: `target[..]foo[..]` (exit [..]: 2)", - ); - } - - p.cargo("run -v").with_status(2).with_stderr(output).run(); +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] `target/debug/foo[EXE]` +[ERROR] process didn't exit successfully: `target/debug/foo[EXE]` ([EXIT_STATUS]: 2) + +"#]] + } else { + str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[RUNNING] `rustc [..]` +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] `target/debug/foo[EXE]` + +"#]] + }; + + p.cargo("run -v") + .with_status(2) + .with_stderr_data(expected) + .run(); } #[cargo_test] @@ -283,10 +330,10 @@ fn no_main_file() { p.cargo("run") .with_status(101) - .with_stderr( - "[ERROR] a bin target must be available \ - for `cargo run`\n", - ) + .with_stderr_data(str![[r#" +[ERROR] a bin target must be available for `cargo run` + +"#]]) .run(); } @@ -301,12 +348,11 @@ fn too_many_bins() { // Using [..] here because the order is not stable p.cargo("run") .with_status(101) - .with_stderr( - "[ERROR] `cargo run` could not determine which binary to run. \ - Use the `--bin` option to specify a binary, or the \ - `default-run` manifest key.\ - \navailable binaries: [..]\n", - ) + .with_stderr_data(str![[r#" +[ERROR] `cargo run` could not determine which binary to run. Use the `--bin` option to specify a binary, or the `default-run` manifest key. +available binaries: a, b + +"#]]) .run(); } @@ -333,26 +379,32 @@ fn specify_name() { .build(); p.cargo("run --bin a -v") - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([CWD]) + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) [RUNNING] `rustc [..] src/lib.rs [..]` [RUNNING] `rustc [..] src/bin/a.rs [..]` -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -[RUNNING] `target/debug/a[EXE]`", - ) - .with_stdout("hello a.rs") +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] `target/debug/a[EXE]` + +"#]]) + .with_stdout_data(str![[r#" +hello a.rs + +"#]]) .run(); p.cargo("run --bin b -v") - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([..]) + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) [RUNNING] `rustc [..] src/bin/b.rs [..]` -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -[RUNNING] `target/debug/b[EXE]`", - ) - .with_stdout("hello b.rs") +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] `target/debug/b[EXE]` + +"#]]) + .with_stdout_data(str![[r#" +hello b.rs + +"#]]) .run(); } @@ -375,9 +427,24 @@ fn specify_default_run() { .file("src/bin/b.rs", r#"fn main() { println!("hello B"); }"#) .build(); - p.cargo("run").with_stdout("hello A").run(); - p.cargo("run --bin a").with_stdout("hello A").run(); - p.cargo("run --bin b").with_stdout("hello B").run(); + p.cargo("run") + .with_stdout_data(str![[r#" +hello A + +"#]]) + .run(); + p.cargo("run --bin a") + .with_stdout_data(str![[r#" +hello A + +"#]]) + .run(); + p.cargo("run --bin b") + .with_stdout_data(str![[r#" +hello B + +"#]]) + .run(); } #[cargo_test] @@ -400,16 +467,15 @@ fn bogus_default_run() { p.cargo("run") .with_status(101) - .with_stderr( - "\ -[ERROR] failed to parse manifest at `[..]/foo/Cargo.toml` + .with_stderr_data(str![[r#" +[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml` Caused by: default-run target `b` not found - Did you mean `a`? -", - ) + Did you mean `a`? + +"#]]) .run(); } @@ -422,13 +488,16 @@ fn run_example() { .build(); p.cargo("run --example a") - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -[RUNNING] `target/debug/examples/a[EXE]`", - ) - .with_stdout("example") + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] `target/debug/examples/a[EXE]` + +"#]]) + .with_stdout_data(str![[r#" +example + +"#]]) .run(); } @@ -454,7 +523,10 @@ fn run_library_example() { p.cargo("run --example bar") .with_status(101) - .with_stderr("[ERROR] example target `bar` is a library and cannot be executed") + .with_stderr_data(str![[r#" +[ERROR] example target `bar` is a library and cannot be executed + +"#]]) .run(); } @@ -478,13 +550,16 @@ fn run_bin_example() { .build(); p.cargo("run --example bar") - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -[RUNNING] `target/debug/examples/bar[EXE]`", - ) - .with_stdout("example") + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] `target/debug/examples/bar[EXE]` + +"#]]) + .with_stdout_data(str![[r#" +example + +"#]]) .run(); } @@ -531,14 +606,13 @@ fn run_example_autodiscover_2015() { let p = autodiscover_examples_project("2015", None); p.cargo("run --example a") .with_status(101) - .with_stderr( - "warning: \ -An explicit [[example]] section is specified in Cargo.toml which currently + .with_stderr_data(str![[r#" +[WARNING] An explicit [[example]] section is specified in Cargo.toml which currently disables Cargo from automatically inferring other example targets. This inference behavior will change in the Rust 2018 edition and the following files will be included as a example target: -* [..]a.rs +* examples/a.rs This is likely to break cargo build or cargo test as these files may not be ready to be compiled as a example target today. You can future-proof yourself @@ -548,12 +622,12 @@ automatically infer them to be a target, such as in subfolders. For more information on this warning you can consult https://github.com/rust-lang/cargo/issues/5330 -error: no example target named `a`. +[ERROR] no example target named `a`. Available example targets: do_magic -", - ) + +"#]]) .run(); } @@ -561,13 +635,16 @@ Available example targets: fn run_example_autodiscover_2015_with_autoexamples_enabled() { let p = autodiscover_examples_project("2015", Some(true)); p.cargo("run --example a") - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -[RUNNING] `target/debug/examples/a[EXE]`", - ) - .with_stdout("example") + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] `target/debug/examples/a[EXE]` + +"#]]) + .with_stdout_data(str![[r#" +example + +"#]]) .run(); } @@ -576,14 +653,13 @@ fn run_example_autodiscover_2015_with_autoexamples_disabled() { let p = autodiscover_examples_project("2015", Some(false)); p.cargo("run --example a") .with_status(101) - .with_stderr( - "\ -error: no example target named `a`. + .with_stderr_data(str![[r#" +[ERROR] no example target named `a`. Available example targets: do_magic -", - ) + +"#]]) .run(); } @@ -591,13 +667,16 @@ Available example targets: fn run_example_autodiscover_2018() { let p = autodiscover_examples_project("2018", None); p.cargo("run --example a") - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -[RUNNING] `target/debug/examples/a[EXE]`", - ) - .with_stdout("example") + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] `target/debug/examples/a[EXE]` + +"#]]) + .with_stdout_data(str![[r#" +example + +"#]]) .run(); } @@ -620,7 +699,10 @@ fn autobins_disables() { p.cargo("run") .with_status(101) - .with_stderr("[ERROR] a bin target must be available for `cargo run`") + .with_stderr_data(str![[r#" +[ERROR] a bin target must be available for `cargo run` + +"#]]) .run(); } @@ -634,12 +716,12 @@ fn run_bins() { p.cargo("run --bins") .with_status(1) - .with_stderr_contains( - "\ -error: unexpected argument '--bins' found + .with_stderr_data(str![[r#" +[ERROR] unexpected argument '--bins' found - tip: a similar argument exists: '--bin'", - ) + tip: a similar argument exists: '--bin' +... +"#]]) .run(); } @@ -659,46 +741,44 @@ fn run_with_filename() { p.cargo("run --bin bin.rs") .with_status(101) - .with_stderr( - "\ + .with_stderr_data(str![[r#" [ERROR] no bin target named `bin.rs`. Available bin targets: a -", - ) + +"#]]) .run(); p.cargo("run --bin a.rs") .with_status(101) - .with_stderr( - "\ + .with_stderr_data(str![[r#" [ERROR] no bin target named `a.rs` -Did you mean `a`?", - ) + Did you mean `a`? + +"#]]) .run(); p.cargo("run --example example.rs") .with_status(101) - .with_stderr( - "\ + .with_stderr_data(str![[r#" [ERROR] no example target named `example.rs`. Available example targets: a -", - ) + +"#]]) .run(); p.cargo("run --example a.rs") .with_status(101) - .with_stderr( - "\ + .with_stderr_data(str![[r#" [ERROR] no example target named `a.rs` -Did you mean `a`?", - ) + Did you mean `a`? + +"#]]) .run(); } @@ -711,11 +791,10 @@ fn either_name_or_example() { p.cargo("run --bin a --example b") .with_status(101) - .with_stderr( - "[ERROR] `cargo run` can run at most one \ - executable, but multiple were \ - specified", - ) + .with_stderr_data(str![[r#" +[ERROR] `cargo run` can run at most one executable, but multiple were specified + +"#]]) .run(); } @@ -732,13 +811,16 @@ fn one_bin_multiple_examples() { .build(); p.cargo("run") - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -[RUNNING] `target/debug/main[EXE]`", - ) - .with_stdout("hello main.rs") + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] `target/debug/main[EXE]` + +"#]]) + .with_stdout_data(str![[r#" +hello main.rs + +"#]]) .run(); } @@ -790,64 +872,38 @@ fn example_with_release_flag() { .build(); p.cargo("run -v --release --example a") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [LOCKING] 2 packages to latest compatible versions -[COMPILING] bar v0.5.0 ([CWD]/bar) -[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/bar.rs [..]--crate-type lib \ - --emit=[..]link \ - -C opt-level=3[..]\ - -C metadata=[..] \ - --out-dir [CWD]/target/release/deps \ - -C strip=debuginfo \ - -L dependency=[CWD]/target/release/deps` -[COMPILING] foo v0.0.1 ([CWD]) -[RUNNING] `rustc --crate-name a --edition=2015 examples/a.rs [..]--crate-type bin \ - --emit=[..]link \ - -C opt-level=3[..]\ - -C metadata=[..] \ - --out-dir [CWD]/target/release/examples \ - -C strip=debuginfo \ - -L dependency=[CWD]/target/release/deps \ - --extern bar=[CWD]/target/release/deps/libbar-[..].rlib` -[FINISHED] `release` profile [optimized] target(s) in [..] +[COMPILING] bar v0.5.0 ([ROOT]/foo/bar) +[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/bar.rs [..]--crate-type lib --emit=[..]link -C opt-level=3[..] -C metadata=[..] --out-dir [ROOT]/foo/target/release/deps -C strip=debuginfo -L dependency=[ROOT]/foo/target/release/deps` +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[RUNNING] `rustc --crate-name a --edition=2015 examples/a.rs [..]--crate-type bin --emit=[..]link -C opt-level=3[..] -C metadata=[..] --out-dir [ROOT]/foo/target/release/examples -C strip=debuginfo -L dependency=[ROOT]/foo/target/release/deps --extern bar=[ROOT]/foo/target/release/deps/libbar-[HASH].rlib` +[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s [RUNNING] `target/release/examples/a[EXE]` -", - ) - .with_stdout( - "\ + +"#]]) + .with_stdout_data(str![[r#" fast1 -fast2", - ) +fast2 + +"#]]) .run(); p.cargo("run -v --example a") - .with_stderr( - "\ -[COMPILING] bar v0.5.0 ([CWD]/bar) -[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/bar.rs [..]--crate-type lib \ - --emit=[..]link[..]\ - -C debuginfo=2 [..]\ - -C metadata=[..] \ - --out-dir [CWD]/target/debug/deps \ - -L dependency=[CWD]/target/debug/deps` -[COMPILING] foo v0.0.1 ([CWD]) -[RUNNING] `rustc --crate-name a --edition=2015 examples/a.rs [..]--crate-type bin \ - --emit=[..]link[..]\ - -C debuginfo=2 [..]\ - -C metadata=[..] \ - --out-dir [CWD]/target/debug/examples \ - -L dependency=[CWD]/target/debug/deps \ - --extern bar=[CWD]/target/debug/deps/libbar-[..].rlib` -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] + .with_stderr_data(str![[r#" +[COMPILING] bar v0.5.0 ([ROOT]/foo/bar) +[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/bar.rs [..]--crate-type lib --emit=[..]link [..]-C debuginfo=2 [..]-C metadata=[..] --out-dir [ROOT]/foo/target/debug/deps -L dependency=[ROOT]/foo/target/debug/deps` +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[RUNNING] `rustc --crate-name a --edition=2015 examples/a.rs [..]--crate-type bin --emit=[..]link [..]-C debuginfo=2 [..]-C metadata=[..] --out-dir [ROOT]/foo/target/debug/examples -L dependency=[ROOT]/foo/target/debug/deps --extern bar=[ROOT]/foo/target/debug/deps/libbar-[HASH].rlib` +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s [RUNNING] `target/debug/examples/a[EXE]` -", - ) - .with_stdout( - "\ + +"#]]) + .with_stdout_data(str![[r#" slow1 -slow2", - ) +slow2 + +"#]]) .run(); } @@ -923,15 +979,18 @@ fn run_with_bin_dep() { .build(); p.cargo("run") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [LOCKING] 2 packages to latest compatible versions -[WARNING] foo v0.0.1 ([CWD]) ignoring invalid dependency `bar` which is missing a lib target -[COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -[RUNNING] `target/debug/foo[EXE]`", - ) - .with_stdout("hello") +[WARNING] foo v0.0.1 ([ROOT]/foo) ignoring invalid dependency `bar` which is missing a lib target +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] `target/debug/foo[EXE]` + +"#]]) + .with_stdout_data(str![[r#" +hello + +"#]]) .run(); } @@ -984,16 +1043,19 @@ fn run_with_bin_deps() { .build(); p.cargo("run") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [LOCKING] 3 packages to latest compatible versions -[WARNING] foo v0.0.1 ([CWD]) ignoring invalid dependency `bar1` which is missing a lib target -[WARNING] foo v0.0.1 ([CWD]) ignoring invalid dependency `bar2` which is missing a lib target -[COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -[RUNNING] `target/debug/foo[EXE]`", - ) - .with_stdout("hello") +[WARNING] foo v0.0.1 ([ROOT]/foo) ignoring invalid dependency `bar1` which is missing a lib target +[WARNING] foo v0.0.1 ([ROOT]/foo) ignoring invalid dependency `bar2` which is missing a lib target +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] `target/debug/foo[EXE]` + +"#]]) + .with_stdout_data(str![[r#" +hello + +"#]]) .run(); } @@ -1071,24 +1133,27 @@ fn run_with_bin_dep_in_workspace() { p.cargo("run") .with_status(101) - .with_stderr( - "\ -[ERROR] `cargo run` could not determine which binary to run[..] -available binaries: bar1, bar2, foo1, foo2", - ) + .with_stderr_data(str![[r#" +[ERROR] `cargo run` could not determine which binary to run. Use the `--bin` option to specify a binary, or the `default-run` manifest key. +available binaries: bar1, bar2, foo1, foo2 + +"#]]) .run(); p.cargo("run --bin foo1") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [LOCKING] 4 packages to latest compatible versions -[WARNING] foo1 v0.0.1 ([CWD]/foo1) ignoring invalid dependency `bar1` which is missing a lib target -[WARNING] foo2 v0.0.1 ([CWD]/foo2) ignoring invalid dependency `bar2` which is missing a lib target -[COMPILING] foo1 v0.0.1 ([CWD]/foo1) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -[RUNNING] `target/debug/foo1[EXE]`", - ) - .with_stdout("hello") +[WARNING] foo1 v0.0.1 ([ROOT]/foo/foo1) ignoring invalid dependency `bar1` which is missing a lib target +[WARNING] foo2 v0.0.1 ([ROOT]/foo/foo2) ignoring invalid dependency `bar2` which is missing a lib target +[COMPILING] foo1 v0.0.1 ([ROOT]/foo/foo1) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] `target/debug/foo1[EXE]` + +"#]]) + .with_stdout_data(str![[r#" +hello + +"#]]) .run(); } @@ -1104,13 +1169,12 @@ fn release_works() { .build(); p.cargo("run --release") - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] `release` profile [optimized] target(s) in [..] + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s [RUNNING] `target/release/foo[EXE]` -", - ) + +"#]]) .run(); assert!(p.release_bin("foo").is_file()); } @@ -1127,13 +1191,12 @@ fn release_short_works() { .build(); p.cargo("run -r") - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] `release` profile [optimized] target(s) in [..] + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s [RUNNING] `target/release/foo[EXE]` -", - ) + +"#]]) .run(); assert!(p.release_bin("foo").is_file()); } @@ -1191,11 +1254,15 @@ fn run_from_executable_folder() { p.cargo("run") .cwd(cwd) - .with_stderr( - "[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]\n\ - [RUNNING] `./foo[EXE]`", - ) - .with_stdout("hello") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] `./foo[EXE]` + +"#]]) + .with_stdout_data(str![[r#" +hello + +"#]]) .run(); } @@ -1327,8 +1394,8 @@ fn fail_no_extra_verbose() { p.cargo("run -q") .with_status(1) - .with_stdout("") - .with_stderr("") + .with_stdout_data("") + .with_stderr_data("") .run(); } @@ -1372,17 +1439,32 @@ fn run_multiple_packages() { process_builder }; - cargo().arg("-p").arg("d1").with_stdout("d1").run(); + cargo() + .arg("-p") + .arg("d1") + .with_stdout_data(str![[r#" +d1 + +"#]]) + .run(); cargo() .arg("-p") .arg("d2") .arg("--bin") .arg("d2") - .with_stdout("d2") + .with_stdout_data(str![[r#" +d2 + +"#]]) .run(); - cargo().with_stdout("foo").run(); + cargo() + .with_stdout_data(str![[r#" +foo + +"#]]) + .run(); cargo() .arg("-p") @@ -1390,25 +1472,30 @@ fn run_multiple_packages() { .arg("-p") .arg("d2") .with_status(1) - .with_stderr_contains( - "error: the argument '--package []' cannot be used multiple times", - ) + .with_stderr_data(str![[r#" +[ERROR] the argument '--package []' cannot be used multiple times +... +"#]]) .run(); cargo() .arg("-p") .arg("d3") .with_status(101) - .with_stderr_contains("[ERROR] package(s) `d3` not found in workspace [..]") + .with_stderr_data(str![[r#" +[ERROR] package(s) `d3` not found in workspace `[ROOT]/foo/foo` + +"#]]) .run(); cargo() .arg("-p") .arg("d*") .with_status(101) - .with_stderr_contains( - "[ERROR] `cargo run` does not support glob pattern `d*` on package selection", - ) + .with_stderr_data(str![[r#" +[ERROR] `cargo run` does not support glob pattern `d*` on package selection + +"#]]) .run(); } @@ -1447,13 +1534,18 @@ fn run_workspace() { p.cargo("run") .with_status(101) - .with_stderr( - "\ -[ERROR] `cargo run` could not determine which binary to run[..] -available binaries: a, b", - ) + .with_stderr_data(str![[r#" +[ERROR] `cargo run` could not determine which binary to run. Use the `--bin` option to specify a binary, or the `default-run` manifest key. +available binaries: a, b + +"#]]) + .run(); + p.cargo("run --bin a") + .with_stdout_data(str![[r#" +run-a + +"#]]) .run(); - p.cargo("run --bin a").with_stdout("run-a").run(); } #[cargo_test] @@ -1481,7 +1573,12 @@ fn default_run_workspace() { .file("b/src/main.rs", r#"fn main() {println!("run-b");}"#) .build(); - p.cargo("run").with_stdout("run-a").run(); + p.cargo("run") + .with_stdout_data(str![[r#" +run-a + +"#]]) + .run(); } #[cargo_test] @@ -1492,13 +1589,13 @@ fn print_env_verbose() { .build(); p.cargo("run -vv") - .with_stderr( - "\ -[COMPILING] a v0.0.1 ([CWD]) -[RUNNING] `[..]CARGO_MANIFEST_DIR=[CWD][..] rustc --crate-name a[..]` -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -[RUNNING] `[..]CARGO_MANIFEST_DIR=[CWD][..] target/debug/a[EXE]`", - ) + .with_stderr_data(str![[r#" +[COMPILING] a v0.0.1 ([ROOT]/foo) +[RUNNING] `[..]CARGO_MANIFEST_DIR=[ROOT]/foo[..] rustc --crate-name a[..]` +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] `[..]CARGO_MANIFEST_DIR=[ROOT]/foo[..] target/debug/a[EXE]` + +"#]]) .run(); } @@ -1639,6 +1736,9 @@ fn run_binary_with_same_name_as_dependency() { p.cargo("run -p foo@0.5").run(); p.cargo("run -p foo@0.4") .with_status(101) - .with_stderr("[ERROR] package(s) `foo@0.4` not found in workspace `[..]`") + .with_stderr_data(str![[r#" +[ERROR] package(s) `foo@0.4` not found in workspace `[ROOT]/foo` + +"#]]) .run(); }