From c3327ed04a95a34f47be5d3f10b9383be2a54c5c Mon Sep 17 00:00:00 2001 From: eth3lbert Date: Thu, 27 Jun 2024 15:23:06 +0800 Subject: [PATCH 1/5] test: migrate local_registry to snapbox --- tests/testsuite/local_registry.rs | 150 +++++++++++++++--------------- 1 file changed, 76 insertions(+), 74 deletions(-) diff --git a/tests/testsuite/local_registry.rs b/tests/testsuite/local_registry.rs index d221f91f45a..750369209c1 100644 --- a/tests/testsuite/local_registry.rs +++ b/tests/testsuite/local_registry.rs @@ -1,10 +1,9 @@ //! Tests for local-registry sources. -#![allow(deprecated)] - use cargo_test_support::paths::{self, CargoPathExt}; +use cargo_test_support::prelude::*; use cargo_test_support::registry::{registry_path, Package}; -use cargo_test_support::{basic_manifest, project, t}; +use cargo_test_support::{basic_manifest, project, str, t}; use std::fs; fn setup() { @@ -52,17 +51,21 @@ fn simple() { .build(); p.cargo("build") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [LOCKING] 2 packages to latest compatible versions -[UNPACKING] bar v0.0.1 ([..]) +[UNPACKING] bar v0.0.1 (registry `[ROOT]/registry`) [COMPILING] bar v0.0.1 -[COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] [..] -", - ) +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) + .run(); + p.cargo("build") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); - p.cargo("build").with_stderr("[FINISHED] [..]").run(); p.cargo("test").run(); } @@ -95,13 +98,12 @@ fn not_found() { p.cargo("check") .with_status(101) - .with_stderr( - "\ + .with_stderr_data(str![[r#" [ERROR] no matching package named `baz` found location searched: registry `crates-io` -required by package `foo v0.0.1 ([..]/foo)` -", - ) +required by package `foo v0.0.1 ([ROOT]/foo)` + +"#]]) .run(); } @@ -137,11 +139,10 @@ fn depend_on_yanked() { .publish(); p.cargo("check") - .with_stderr( - "\ -[FINISHED] [..] -", - ) + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -175,15 +176,14 @@ fn multiple_versions() { .build(); p.cargo("check") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [LOCKING] 2 packages to latest compatible versions -[UNPACKING] bar v0.1.0 ([..]) +[UNPACKING] bar v0.1.0 (registry `[ROOT]/registry`) [CHECKING] bar v0.1.0 -[CHECKING] foo v0.0.1 ([CWD]) -[FINISHED] [..] -", - ) +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); Package::new("bar", "0.2.0") @@ -192,11 +192,11 @@ fn multiple_versions() { .publish(); p.cargo("update") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [LOCKING] 1 package to latest compatible version -[UPDATING] bar v0.1.0 -> v0.2.0", - ) +[UPDATING] bar v0.1.0 -> v0.2.0 + +"#]]) .run(); } @@ -241,16 +241,18 @@ fn multiple_names() { .build(); p.cargo("check") - .with_stderr( - "\ + .with_stderr_data( + str![[r#" [LOCKING] 3 packages to latest compatible versions -[UNPACKING] [..] -[UNPACKING] [..] -[CHECKING] [..] -[CHECKING] [..] -[CHECKING] foo v0.0.1 ([CWD]) -[FINISHED] [..] -", +[UNPACKING] bar v0.0.1 (registry `[ROOT]/registry`) +[UNPACKING] baz v0.1.0 (registry `[ROOT]/registry`) +[CHECKING] bar v0.0.1 +[CHECKING] baz v0.1.0 +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]] + .unordered(), ) .run(); } @@ -297,17 +299,16 @@ fn interdependent() { .build(); p.cargo("check") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [LOCKING] 3 packages to latest compatible versions -[UNPACKING] [..] -[UNPACKING] [..] +[UNPACKING] bar v0.0.1 (registry `[ROOT]/registry`) +[UNPACKING] baz v0.1.0 (registry `[ROOT]/registry`) [CHECKING] bar v0.0.1 [CHECKING] baz v0.1.0 -[CHECKING] foo v0.0.1 ([CWD]) -[FINISHED] [..] -", - ) +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -368,17 +369,16 @@ fn path_dep_rewritten() { .build(); p.cargo("check") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [LOCKING] 3 packages to latest compatible versions -[UNPACKING] [..] -[UNPACKING] [..] +[UNPACKING] bar v0.0.1 (registry `[ROOT]/registry`) +[UNPACKING] baz v0.1.0 (registry `[ROOT]/registry`) [CHECKING] bar v0.0.1 [CHECKING] baz v0.1.0 -[CHECKING] foo v0.0.1 ([CWD]) -[FINISHED] [..] -", - ) +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -415,9 +415,8 @@ fn invalid_dir_bad() { p.cargo("check") .with_status(101) - .with_stderr( - "\ -[ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 [..]` + .with_stderr_data(str![[r#" +[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` @@ -430,8 +429,8 @@ Caused by: Caused by: local registry path is not a directory: [..]path[..]to[..]nowhere -", - ) + +"#]]) .run(); } @@ -478,8 +477,7 @@ fn different_directory_replacing_the_registry_is_bad() { p.cargo("check") .with_status(101) - .with_stderr( - "\ + .with_stderr_data(str![[r#" [ERROR] checksum for `bar v0.0.1` changed between lock files this could be indicative of a few possible errors: @@ -490,8 +488,8 @@ this could be indicative of a few possible errors: unable to verify that `bar v0.0.1` is the same as when the lockfile was generated -", - ) + +"#]]) .run(); } @@ -536,16 +534,20 @@ fn crates_io_registry_url_is_optional() { .build(); p.cargo("build") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [LOCKING] 2 packages to latest compatible versions -[UNPACKING] bar v0.0.1 ([..]) +[UNPACKING] bar v0.0.1 (registry `[ROOT]/registry`) [COMPILING] bar v0.0.1 -[COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] [..] -", - ) +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) + .run(); + p.cargo("build") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); - p.cargo("build").with_stderr("[FINISHED] [..]").run(); p.cargo("test").run(); } From 02c0f7ef57da50e643c778e97d10be52b4f2e254 Mon Sep 17 00:00:00 2001 From: eth3lbert Date: Thu, 27 Jun 2024 15:29:31 +0800 Subject: [PATCH 2/5] test: migrate locate_project to snapbox --- tests/testsuite/locate_project.rs | 73 +++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 13 deletions(-) diff --git a/tests/testsuite/locate_project.rs b/tests/testsuite/locate_project.rs index 2e350b1ac2f..9ffa43c9614 100644 --- a/tests/testsuite/locate_project.rs +++ b/tests/testsuite/locate_project.rs @@ -1,15 +1,22 @@ //! Tests for the `cargo locate-project` command. -#![allow(deprecated)] - +use cargo_test_support::prelude::*; use cargo_test_support::project; +use cargo_test_support::str; #[cargo_test] fn simple() { let p = project().build(); p.cargo("locate-project") - .with_json(r#"{"root": "[ROOT]/foo/Cargo.toml"}"#) + .with_stdout_data( + str![[r#" +{ + "root": "[ROOT]/foo/Cargo.toml" +} +"#]] + .json(), + ) .run(); } @@ -18,15 +25,28 @@ fn message_format() { let p = project().build(); p.cargo("locate-project --message-format plain") - .with_stdout("[ROOT]/foo/Cargo.toml") + .with_stdout_data(str![[r#" +[ROOT]/foo/Cargo.toml + +"#]]) .run(); p.cargo("locate-project --message-format json") - .with_json(r#"{"root": "[ROOT]/foo/Cargo.toml"}"#) + .with_stdout_data( + str![[r#" +{ + "root": "[ROOT]/foo/Cargo.toml" +} +"#]] + .json(), + ) .run(); p.cargo("locate-project --message-format cryptic") - .with_stderr("error: invalid message format specifier: `cryptic`") + .with_stderr_data(str![[r#" +[ERROR] invalid message format specifier: `cryptic` + +"#]]) .with_status(101) .run(); } @@ -57,22 +77,49 @@ fn workspace() { .file("inner/src/lib.rs", "") .build(); - let outer_manifest = r#"{"root": "[ROOT]/foo/Cargo.toml"}"#; - let inner_manifest = r#"{"root": "[ROOT]/foo/inner/Cargo.toml"}"#; - - p.cargo("locate-project").with_json(outer_manifest).run(); + p.cargo("locate-project") + .with_stdout_data( + str![[r#" +{ + "root": "[ROOT]/foo/Cargo.toml" +} +"#]] + .json(), + ) + .run(); p.cargo("locate-project") .cwd("inner") - .with_json(inner_manifest) + .with_stdout_data( + str![[r#" +{ + "root": "[ROOT]/foo/inner/Cargo.toml" +} +"#]] + .json(), + ) .run(); p.cargo("locate-project --workspace") - .with_json(outer_manifest) + .with_stdout_data( + str![[r#" +{ + "root": "[ROOT]/foo/Cargo.toml" +} +"#]] + .json(), + ) .run(); p.cargo("locate-project --workspace") .cwd("inner") - .with_json(outer_manifest) + .with_stdout_data( + str![[r#" +{ + "root": "[ROOT]/foo/Cargo.toml" +} +"#]] + .json(), + ) .run(); } From 6d0825dc2944b2e23d994c6c9a524853069b856f Mon Sep 17 00:00:00 2001 From: eth3lbert Date: Thu, 27 Jun 2024 15:38:33 +0800 Subject: [PATCH 3/5] test: migrate lockfile_compat to snapbox --- tests/testsuite/lockfile_compat.rs | 155 ++++++++++++----------------- 1 file changed, 66 insertions(+), 89 deletions(-) diff --git a/tests/testsuite/lockfile_compat.rs b/tests/testsuite/lockfile_compat.rs index 9496a88f64b..42cbf963699 100644 --- a/tests/testsuite/lockfile_compat.rs +++ b/tests/testsuite/lockfile_compat.rs @@ -1,7 +1,5 @@ //! Tests for supporting older versions of the Cargo.lock file format. -#![allow(deprecated)] - use cargo_test_support::compare::assert_e2e; use cargo_test_support::git; use cargo_test_support::registry::Package; @@ -236,10 +234,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" p.cargo("check") .with_status(101) - .with_stderr( - "\ -[UPDATING] `[..]` index -error: checksum for `bar v0.1.0` changed between lock files + .with_stderr_data(str![[r#" +[UPDATING] `dummy-registry` index +[ERROR] checksum for `bar v0.1.0` changed between lock files this could be indicative of a few possible errors: @@ -249,8 +246,8 @@ this could be indicative of a few possible errors: unable to verify that `bar v0.1.0` is the same as when the lockfile was generated -", - ) + +"#]]) .run(); } @@ -297,25 +294,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" ); let p = p.build(); - p.cargo("fetch") - .with_status(101) - .with_stderr( - "\ -[UPDATING] `[..]` index -error: checksum for `bar v0.1.0` was not previously calculated, but a checksum \ -could now be calculated + p.cargo("fetch").with_status(101).with_stderr_data(str![[r#" +[UPDATING] `dummy-registry` index +[ERROR] checksum for `bar v0.1.0` was not previously calculated, but a checksum could now be calculated this could be indicative of a few possible situations: - * the source `[..]` did not previously support checksums, + * the source `registry `crates-io`` did not previously support checksums, but was replaced with one that does * newer Cargo implementations know how to checksum this source, but this older implementation does not * the lock file is corrupt -", - ) - .run(); + +"#]]).run(); } // If the checksum is listed in the lock file yet we cannot calculate it (e.g., @@ -370,25 +362,20 @@ source = "git+{0}" let p = p.build(); - p.cargo("fetch") - .with_status(101) - .with_stderr( - "\ -[UPDATING] git repository `[..]` -error: checksum for `bar v0.1.0 ([..])` could not be calculated, but a \ -checksum is listed in the existing lock file[..] + p.cargo("fetch").with_status(101).with_stderr_data(str![[r#" +[UPDATING] git repository `[ROOTURL]/bar` +[ERROR] checksum for `bar v0.1.0 ([ROOTURL]/bar)` could not be calculated, but a checksum is listed in the existing lock file this could be indicative of a few possible situations: - * the source `[..]` supports checksums, + * the source `[ROOTURL]/bar` supports checksums, but was replaced with one that doesn't * the lock file is corrupt -unable to verify that `bar v0.1.0 ([..])` is the same as when the lockfile was generated +unable to verify that `bar v0.1.0 ([ROOTURL]/bar)` is the same as when the lockfile was generated -", - ) - .run(); + +"#]]).run(); } #[cargo_test] @@ -527,14 +514,12 @@ fn locked_correct_error() { p.cargo("check --locked") .with_status(101) - .with_stderr( - "\ -[UPDATING] `[..]` index -error: the lock file [CWD]/Cargo.lock needs to be updated but --locked was passed to prevent this -If you want to try to generate the lock file without accessing the network, \ -remove the --locked flag and use --offline instead. -", - ) + .with_stderr_data(str![[r#" +[UPDATING] `dummy-registry` index +[ERROR] the lock file [ROOT]/foo/Cargo.lock needs to be updated but --locked was passed to prevent this +If you want to try to generate the lock file without accessing the network, remove the --locked flag and use --offline instead. + +"#]]) .run(); } @@ -731,18 +716,13 @@ fn lock_from_the_future() { .file("Cargo.lock", "version = 10000000") .build(); - p.cargo("fetch") - .with_stderr( - "\ -error: failed to parse lock file at: [..] + p.cargo("fetch").with_stderr_data(str![[r#" +[ERROR] failed to parse lock file at: [ROOT]/foo/Cargo.lock Caused by: - lock file version `10000000` was found, but this version of Cargo does not \ - understand this lock file, perhaps Cargo needs to be updated? -", - ) - .with_status(101) - .run(); + lock file version `10000000` was found, but this version of Cargo does not understand this lock file, perhaps Cargo needs to be updated? + +"#]]).with_status(101).run(); } #[cargo_test] @@ -904,16 +884,15 @@ dependencies = [ .build(); p.cargo("check") .with_status(101) - .with_stderr( - "\ -[..] -[ERROR] failed to select a version for the requirement `bar = \"*\"` (locked to 0.1.0) + .with_stderr_data(str![[r#" +[UPDATING] `dummy-registry` index +[ERROR] failed to select a version for the requirement `bar = "*"` (locked to 0.1.0) candidate versions found which didn't match: 0.0.1 location searched: `dummy-registry` index (which is replacing registry `crates-io`) -required by package `test v0.0.0 ([..])` +required by package `test v0.0.0 ([ROOT]/foo)` perhaps a crate was updated and forgotten to be re-vendored? -", - ) + +"#]]) .run(); } @@ -935,31 +914,25 @@ fn next_version_is_always_unstable() { .file("Cargo.lock", "version = 5") .build(); - p.cargo("fetch") - .with_status(101) - .with_stderr( - "\ -error: failed to parse lock file at: [CWD]/Cargo.lock + p.cargo("fetch").with_status(101).with_stderr_data(str![[r#" +[ERROR] failed to parse lock file at: [ROOT]/foo/Cargo.lock Caused by: - lock file version `5` was found, but this version of Cargo does not \ - understand this lock file, perhaps Cargo needs to be updated? -", - ) - .run(); + lock file version `5` was found, but this version of Cargo does not understand this lock file, perhaps Cargo needs to be updated? + +"#]]).run(); // On nightly, let the user know about the `-Z` flag. p.cargo("fetch") .masquerade_as_nightly_cargo(&["-Znext-lockfile-bump"]) .with_status(101) - .with_stderr( - "\ -error: failed to parse lock file at: [CWD]/Cargo.lock + .with_stderr_data(str![[r#" +[ERROR] failed to parse lock file at: [ROOT]/foo/Cargo.lock Caused by: lock file version `5` requires `-Znext-lockfile-bump` -", - ) + +"#]]) .run(); } @@ -1062,15 +1035,15 @@ dependencies = [ .build(); p.cargo("check") - .with_stderr(format!( + .with_stderr_data(format!( "\ -[UPDATING] git repository `{url}` +[UPDATING] git repository `[ROOTURL]/dep1` [LOCKING] 2 packages to latest compatible versions -[ADDING] dep1 v0.5.0 ({url}?{ref_kind}={git_ref}#[..]) -[ADDING] foo v0.0.1 ([CWD]) -[CHECKING] dep1 v0.5.0 ({url}?{ref_kind}={git_ref}#[..]) -[CHECKING] foo v0.0.1 ([CWD]) -[FINISHED] `dev` profile [..] +[ADDING] dep1 v0.5.0 ([ROOTURL]/dep1?{ref_kind}={git_ref}#[..]) +[ADDING] foo v0.0.1 ([ROOT]/foo) +[CHECKING] dep1 v0.5.0 ([ROOTURL]/dep1?{ref_kind}={git_ref}#[..]) +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s " )) .run(); @@ -1082,10 +1055,10 @@ dependencies = [ // was URL-encoded. Therefore Cargo thinks they are from different source // and clones the repository again. p.cargo("check") - .with_stderr(format!( + .with_stderr_data(format!( "\ -[UPDATING] git repository `{url}` -[FINISHED] `dev` profile [..] +[UPDATING] git repository `[ROOTURL]/dep1` +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s " )) .run(); @@ -1158,15 +1131,15 @@ dependencies = [ .build(); p.cargo("check") - .with_stderr(format!( + .with_stderr_data(format!( "\ -[UPDATING] git repository `{url}` +[UPDATING] git repository `[ROOTURL]/dep1` [LOCKING] 2 packages to latest compatible versions -[ADDING] dep1 v0.5.0 ({url}?{ref_kind}={git_ref}#[..]) -[ADDING] foo v0.0.1 ([CWD]) -[CHECKING] dep1 v0.5.0 ({url}?{ref_kind}={git_ref}#[..]) -[CHECKING] foo v0.0.1 ([CWD]) -[FINISHED] `dev` profile [..] +[ADDING] dep1 v0.5.0 ([ROOTURL]/dep1?{ref_kind}={git_ref}#[..]) +[ADDING] foo v0.0.1 ([ROOT]/foo) +[CHECKING] dep1 v0.5.0 ([ROOTURL]/dep1?{ref_kind}={git_ref}#[..]) +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s " )) .run(); @@ -1177,7 +1150,11 @@ dependencies = [ // Unlike v3_and_git_url_encoded, v4 encodes URL parameters so no git // repository re-clone happen. p.cargo("check") - .with_stderr("[FINISHED] `dev` profile [..]") + .with_stderr_data( + "\ +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +", + ) .run(); } From 56471efb3f6753c755e42bad74b1a01e4056f1d4 Mon Sep 17 00:00:00 2001 From: eth3lbert Date: Thu, 27 Jun 2024 15:49:05 +0800 Subject: [PATCH 4/5] test: migrate login to snapbox --- tests/testsuite/login.rs | 80 ++++++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 31 deletions(-) diff --git a/tests/testsuite/login.rs b/tests/testsuite/login.rs index 4d15644a0c4..f730f3d0a4d 100644 --- a/tests/testsuite/login.rs +++ b/tests/testsuite/login.rs @@ -1,10 +1,9 @@ //! Tests for the `cargo login` command. -#![allow(deprecated)] - use cargo_test_support::cargo_process; use cargo_test_support::paths::{self, CargoPathExt}; use cargo_test_support::registry::{self, RegistryBuilder}; +use cargo_test_support::str; use cargo_test_support::t; use std::fs; use std::path::PathBuf; @@ -112,30 +111,28 @@ fn empty_login_token() { cargo_process("login") .replace_crates_io(registry.index_url()) .with_stdin("\t\n") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [UPDATING] crates.io index -please paste the token found on [..] below +please paste the token found on [ROOTURL]/api/me below [ERROR] credential provider `cargo:token` failed action `login` Caused by: please provide a non-empty token -", - ) + +"#]]) .with_status(101) .run(); cargo_process("login") .replace_crates_io(registry.index_url()) .arg("") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [ERROR] credential provider `cargo:token` failed action `login` Caused by: please provide a non-empty token -", - ) + +"#]]) .with_status(101) .run(); } @@ -152,7 +149,7 @@ fn invalid_login_token() { cargo_process("login") .replace_crates_io(registry.index_url()) .with_stdin(stdin) - .with_stderr(stderr) + .with_stderr_data(stderr) .with_status(status) .run(); }; @@ -164,11 +161,20 @@ fn invalid_login_token() { Caused by: token contains invalid characters. - Only printable ISO-8859-1 characters are allowed as it is sent in a HTTPS header.", + Only printable ISO-8859-1 characters are allowed as it is sent in a HTTPS header. +", 101, ) }; - let valid = |stdin: &str| check(stdin, "[LOGIN] token for `crates-io` saved", 0); + let valid = |stdin: &str| { + check( + stdin, + "\ +[LOGIN] token for `crates-io` saved +", + 0, + ) + }; // Update config.json so that the rest of the tests don't need to care // whether or not `Updating` is printed. @@ -203,9 +209,16 @@ fn bad_asymmetric_token_args() { cargo_process("login -Zasymmetric-token -- --key-subject") .masquerade_as_nightly_cargo(&["asymmetric-token"]) .replace_crates_io(registry.index_url()) - .with_stderr_contains( - " error: a value is required for '--key-subject ' but none was supplied", - ) + .with_stderr_data(str![[r#" +[UPDATING] crates.io index +[ERROR] credential provider `cargo:paseto --key-subject` failed action `login` + +Caused by: + [ERROR] a value is required for '--key-subject ' but none was supplied + + For more information, try '--help'. + +"#]]) .with_status(101) .run(); } @@ -234,10 +247,12 @@ fn login_with_asymmetric_token_and_subject_on_stdin() { cargo_process("login -v -Z asymmetric-token -- --key-subject=foo") .masquerade_as_nightly_cargo(&["asymmetric-token"]) .replace_crates_io(registry.index_url()) - .with_stderr_contains( - "\ -k3.public.AmDwjlyf8jAV3gm5Z7Kz9xAOcsKslt_Vwp5v-emjFzBHLCtcANzTaVEghTNEMj9PkQ", - ) + .with_stderr_data(str![[r#" +[UPDATING] crates.io index +[CREDENTIAL] cargo:paseto --key-subject=foo login crates-io +k3.public.AmDwjlyf8jAV3gm5Z7Kz9xAOcsKslt_Vwp5v-emjFzBHLCtcANzTaVEghTNEMj9PkQ + +"#]]) .with_stdin("k3.secret.fNYVuMvBgOlljt9TDohnaYLblghqaHoQquVZwgR6X12cBFHZLFsaU3q7X3k1Zn36") .run(); let credentials = fs::read_to_string(&credentials).unwrap(); @@ -291,12 +306,12 @@ fn login_with_asymmetric_token_on_stdin() { let credentials = credentials_toml(); cargo_process("login -v -Z asymmetric-token --registry alternative") .masquerade_as_nightly_cargo(&["asymmetric-token"]) - .with_stderr( - "\ -[UPDATING] [..] + .with_stderr_data(str![[r#" +[UPDATING] `alternative` index [CREDENTIAL] cargo:paseto login alternative -k3.public.AmDwjlyf8jAV3gm5Z7Kz9xAOcsKslt_Vwp5v-emjFzBHLCtcANzTaVEghTNEMj9PkQ", - ) +k3.public.AmDwjlyf8jAV3gm5Z7Kz9xAOcsKslt_Vwp5v-emjFzBHLCtcANzTaVEghTNEMj9PkQ + +"#]]) .with_stdin("k3.secret.fNYVuMvBgOlljt9TDohnaYLblghqaHoQquVZwgR6X12cBFHZLFsaU3q7X3k1Zn36") .run(); let credentials = fs::read_to_string(&credentials).unwrap(); @@ -313,7 +328,11 @@ fn login_with_generate_asymmetric_token() { let credentials = credentials_toml(); cargo_process("login -Z asymmetric-token --registry alternative") .masquerade_as_nightly_cargo(&["asymmetric-token"]) - .with_stderr("[UPDATING] `alternative` index\nk3.public.[..]") + .with_stderr_data(str![[r#" +[UPDATING] `alternative` index +k3.public.[..] + +"#]]) .run(); let credentials = fs::read_to_string(&credentials).unwrap(); assert!(credentials.contains("secret-key = \"k3.secret.")); @@ -336,12 +355,11 @@ fn default_registry_configured() { cargo_process("login") .arg("a-new-token") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [UPDATING] `alternative` index [LOGIN] token for `alternative` saved -", - ) + +"#]]) .run(); check_token(None, None); From 8a3787ed5931dbc4ddc82f31f5dc2bd6c4bec1d2 Mon Sep 17 00:00:00 2001 From: eth3lbert Date: Thu, 27 Jun 2024 16:04:20 +0800 Subject: [PATCH 5/5] test: migrate logout to snapbox --- tests/testsuite/logout.rs | 43 +++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/tests/testsuite/logout.rs b/tests/testsuite/logout.rs index 81a22a96981..5b4ab550d1c 100644 --- a/tests/testsuite/logout.rs +++ b/tests/testsuite/logout.rs @@ -1,11 +1,9 @@ //! Tests for the `cargo logout` command. -#![allow(deprecated)] - use super::login::check_token; use cargo_test_support::paths::{self, CargoPathExt}; use cargo_test_support::registry::TestRegistry; -use cargo_test_support::{cargo_process, registry}; +use cargo_test_support::{cargo_process, registry, str}; fn simple_logout_test(registry: &TestRegistry, reg: Option<&str>, flag: &str, note: &str) { let msg = reg.unwrap_or("crates-io"); @@ -15,11 +13,11 @@ fn simple_logout_test(registry: &TestRegistry, reg: Option<&str>, flag: &str, no cargo.replace_crates_io(registry.index_url()); } cargo - .with_stderr(&format!( + .with_stderr_data(&format!( "\ [LOGOUT] token for `{msg}` has been removed from local storage -[NOTE] This does not revoke the token on the registry server.\n \ -If you need to revoke the token, visit {note} and follow the instructions there. +[NOTE] This does not revoke the token on the registry server. + If you need to revoke the token, visit {note} and follow the instructions there. " )) .run(); @@ -30,7 +28,11 @@ If you need to revoke the token, visit {note} and follow the instructions there. cargo.replace_crates_io(registry.index_url()); } cargo - .with_stderr(&format!("[LOGOUT] not currently logged in to `{msg}`")) + .with_stderr_data(&format!( + "\ +[LOGOUT] not currently logged in to `{msg}` +" + )) .run(); check_token(None, reg); } @@ -85,21 +87,20 @@ fn default_registry_configured() { check_token(Some("dummy-token"), Some("dummy-registry")); check_token(Some("crates-io-token"), None); - cargo_process("logout") - .with_stderr( - "\ + cargo_process("logout").with_stderr_data(str![[r#" [LOGOUT] token for `dummy-registry` has been removed from local storage [NOTE] This does not revoke the token on the registry server. - If you need to revoke the token, visit the `dummy-registry` website \ - and follow the instructions there. -", - ) - .run(); + If you need to revoke the token, visit the `dummy-registry` website and follow the instructions there. + +"#]]).run(); check_token(None, Some("dummy-registry")); check_token(Some("crates-io-token"), None); cargo_process("logout") - .with_stderr("[LOGOUT] not currently logged in to `dummy-registry`") + .with_stderr_data(str![[r#" +[LOGOUT] not currently logged in to `dummy-registry` + +"#]]) .run(); } @@ -111,11 +112,17 @@ fn logout_asymmetric() { cargo_process("logout --registry crates-io -Zasymmetric-token") .masquerade_as_nightly_cargo(&["asymmetric-token"]) - .with_stderr("[LOGOUT] secret-key for `crates-io` has been removed from local storage") + .with_stderr_data(str![[r#" +[LOGOUT] secret-key for `crates-io` has been removed from local storage + +"#]]) .run(); cargo_process("logout --registry crates-io -Zasymmetric-token") .masquerade_as_nightly_cargo(&["asymmetric-token"]) - .with_stderr("[LOGOUT] not currently logged in to `crates-io`") + .with_stderr_data(str![[r#" +[LOGOUT] not currently logged in to `crates-io` + +"#]]) .run(); }