From 089dd68d87bede4681474d960bc3cd7c63ef20ed Mon Sep 17 00:00:00 2001 From: eth3lbert Date: Wed, 26 Jun 2024 05:49:13 +0800 Subject: [PATCH 1/3] test: migrate search to snapbox --- tests/testsuite/search.rs | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/tests/testsuite/search.rs b/tests/testsuite/search.rs index 8adf9a6e4a9..391d10c0b41 100644 --- a/tests/testsuite/search.rs +++ b/tests/testsuite/search.rs @@ -1,11 +1,10 @@ //! Tests for the `cargo search` command. -#![allow(deprecated)] - use cargo::util::cache_lock::CacheLockMode; use cargo_test_support::cargo_process; use cargo_test_support::paths; use cargo_test_support::registry::{RegistryBuilder, Response}; +use cargo_test_support::str; use std::collections::HashSet; const SEARCH_API_RESPONSE: &[u8] = br#" @@ -113,8 +112,8 @@ fn not_update() { cargo_process("search postgres") .replace_crates_io(registry.index_url()) - .with_stdout_contains(SEARCH_RESULTS) - .with_stderr("") // without "Updating ... index" + .with_stdout_data(SEARCH_RESULTS) + .with_stderr_data("") // without "Updating ... index" .run(); } @@ -124,8 +123,11 @@ fn replace_default() { cargo_process("search postgres") .replace_crates_io(registry.index_url()) - .with_stdout_contains(SEARCH_RESULTS) - .with_stderr_contains("[..]Updating [..] index") + .with_stdout_data(SEARCH_RESULTS) + .with_stderr_data(str![[r#" +[UPDATING] crates.io index + +"#]]) .run(); } @@ -135,7 +137,7 @@ fn simple() { cargo_process("search postgres --index") .arg(registry.index_url().as_str()) - .with_stdout_contains(SEARCH_RESULTS) + .with_stdout_data(SEARCH_RESULTS) .run(); } @@ -145,7 +147,7 @@ fn multiple_query_params() { cargo_process("search postgres sql --index") .arg(registry.index_url().as_str()) - .with_stdout_contains(SEARCH_RESULTS) + .with_stdout_data(SEARCH_RESULTS) .run(); } @@ -155,10 +157,11 @@ fn ignore_quiet() { cargo_process("search -q postgres") .replace_crates_io(registry.index_url()) - .with_stdout_contains(SEARCH_RESULTS) + .with_stdout_data(SEARCH_RESULTS) .run(); } +#[allow(deprecated)] #[cargo_test] fn colored_results() { let registry = setup().build(); @@ -170,7 +173,13 @@ fn colored_results() { cargo_process("search --color=always postgres") .replace_crates_io(registry.index_url()) - .with_stdout_contains("[..]\x1b[[..]") + .with_stdout_data( + "\ +... +[..]\x1b[[..] +... +", + ) .run(); } @@ -181,7 +190,12 @@ fn auth_required_failure() { cargo_process("search postgres") .replace_crates_io(server.index_url()) .with_status(101) - .with_stderr_contains("[ERROR] no token found, please run `cargo login`") + .with_stderr_data(str![[r#" +[UPDATING] crates.io index +[ERROR] no token found, please run `cargo login` +or use environment variable CARGO_REGISTRY_TOKEN + +"#]]) .run(); } @@ -191,6 +205,6 @@ fn auth_required() { cargo_process("search postgres") .replace_crates_io(server.index_url()) - .with_stdout_contains(SEARCH_RESULTS) + .with_stdout_data(SEARCH_RESULTS) .run(); } From bfe790660ee8516f25e91484f4cf574874cba0c1 Mon Sep 17 00:00:00 2001 From: eth3lbert Date: Wed, 26 Jun 2024 05:20:49 +0800 Subject: [PATCH 2/3] test: migrate source_replacement to snapbox --- tests/testsuite/source_replacement.rs | 84 +++++++++++++-------------- 1 file changed, 39 insertions(+), 45 deletions(-) diff --git a/tests/testsuite/source_replacement.rs b/tests/testsuite/source_replacement.rs index 427559369b4..16ac29f1340 100644 --- a/tests/testsuite/source_replacement.rs +++ b/tests/testsuite/source_replacement.rs @@ -1,11 +1,9 @@ //! Tests for `[source]` table (source replacement). -#![allow(deprecated)] - use std::fs; use cargo_test_support::registry::{Package, RegistryBuilder, TestRegistry}; -use cargo_test_support::{cargo_process, paths, project, t}; +use cargo_test_support::{cargo_process, paths, project, str, t}; fn setup_replacement(config: &str) -> TestRegistry { let crates_io = RegistryBuilder::new() @@ -52,7 +50,10 @@ fn crates_io_token_not_sent_to_replacement() { p.cargo("publish --no-verify --registry crates-io") .replace_crates_io(crates_io.index_url()) - .with_stderr_contains("[UPDATING] crates.io index") + .with_stderr_data(str![[r#" +[UPDATING] crates.io index +... +"#]]) .run(); } @@ -69,22 +70,20 @@ fn token_sent_to_correct_registry() { cargo_process("yank foo@0.0.1 --registry crates-io") .replace_crates_io(crates_io.index_url()) - .with_stderr( - "\ + .with_stderr_data(str![[r#" [UPDATING] crates.io index [YANK] foo@0.0.1 -", - ) + +"#]]) .run(); cargo_process("yank foo@0.0.1 --registry alternative") .replace_crates_io(crates_io.index_url()) - .with_stderr( - "\ + .with_stderr_data(str![[r#" [UPDATING] `alternative` index [YANK] foo@0.0.1 -", - ) + +"#]]) .run(); } @@ -107,12 +106,11 @@ fn ambiguous_registry() { cargo_process("yank foo@0.0.1") .replace_crates_io(crates_io.index_url()) .with_status(101) - .with_stderr( - "\ -error: crates-io is replaced with remote registry alternative; + .with_stderr_data(str![[r#" +[ERROR] crates-io is replaced with remote registry alternative; include `--registry alternative` or `--registry crates-io` -", - ) + +"#]]) .run(); } @@ -132,12 +130,11 @@ fn yank_with_default_crates_io() { cargo_process("yank foo@0.0.1") .replace_crates_io(crates_io.index_url()) - .with_stderr( - "\ + .with_stderr_data(str![[r#" [UPDATING] crates.io index [YANK] foo@0.0.1 -", - ) + +"#]]) .run(); } @@ -157,12 +154,11 @@ fn yank_with_default_alternative() { cargo_process("yank foo@0.0.1") .replace_crates_io(crates_io.index_url()) - .with_stderr( - "\ + .with_stderr_data(str![[r#" [UPDATING] `alternative` index [YANK] foo@0.0.1 -", - ) + +"#]]) .run(); } @@ -209,27 +205,26 @@ fn publish_with_replacement() { // for the verification step. p.cargo("publish --registry crates-io") .replace_crates_io(crates_io.index_url()) - .with_stderr( - "\ + .with_stderr_data(str![[r#" [UPDATING] crates.io index [WARNING] manifest has no documentation, homepage or repository. See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info. -[PACKAGING] foo v0.0.1 ([..]) -[PACKAGED] [..] -[VERIFYING] foo v0.0.1 ([..]) +[PACKAGING] foo v0.0.1 ([ROOT]/foo) +[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed) +[VERIFYING] foo v0.0.1 ([ROOT]/foo) [UPDATING] `alternative` index [DOWNLOADING] crates ... [DOWNLOADED] bar v1.0.0 (registry `alternative`) [COMPILING] bar v1.0.0 -[COMPILING] foo v0.0.1 ([..]foo-0.0.1) -[FINISHED] `dev` profile [..] -[UPLOADING] foo v0.0.1 ([..]) +[COMPILING] foo v0.0.1 ([ROOT]/foo/target/package/foo-0.0.1) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[UPLOADING] foo v0.0.1 ([ROOT]/foo) [UPLOADED] foo v0.0.1 to registry `crates-io` [NOTE] waiting for `foo v0.0.1` to be available at registry `crates-io`. You may press ctrl-c to skip waiting; the crate should be available shortly. [PUBLISHED] foo v0.0.1 at registry `crates-io` -", - ) + +"#]]) .run(); } @@ -246,10 +241,10 @@ fn undefined_default() { cargo_process("yank foo@0.0.1") .replace_crates_io(crates_io.index_url()) .with_status(101) - .with_stderr( - "[ERROR] registry index was not found in any configuration: `undefined` -", - ) + .with_stderr_data(str![[r#" +[ERROR] registry index was not found in any configuration: `undefined` + +"#]]) .run(); } @@ -286,16 +281,15 @@ fn source_replacement_with_registry_url() { p.cargo("check") .replace_crates_io(crates_io.index_url()) - .with_stderr( - "\ + .with_stderr_data(str![[r#" [UPDATING] `using-registry-url` index [LOCKING] 2 packages to latest compatible versions [DOWNLOADING] crates ... [DOWNLOADED] bar v0.0.1 (registry `using-registry-url`) [CHECKING] bar v0.0.1 -[CHECKING] foo v0.0.1 ([CWD]) -[FINISHED] `dev` profile [..] -", - ) +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } From d025f149042ed3270b40b3c5e84b8b8f1e3553f1 Mon Sep 17 00:00:00 2001 From: eth3lbert Date: Wed, 26 Jun 2024 10:50:41 +0800 Subject: [PATCH 3/3] test: migrate standard_lib to snapbox --- tests/testsuite/standard_lib.rs | 62 +++++++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 11 deletions(-) diff --git a/tests/testsuite/standard_lib.rs b/tests/testsuite/standard_lib.rs index 41d1a0e337a..863631a00a6 100644 --- a/tests/testsuite/standard_lib.rs +++ b/tests/testsuite/standard_lib.rs @@ -4,11 +4,9 @@ //! rebuild the real one. There is a separate integration test `build-std` //! which builds the real thing, but that should be avoided if possible. -#![allow(deprecated)] - use cargo_test_support::registry::{Dependency, Package}; use cargo_test_support::ProjectBuilder; -use cargo_test_support::{paths, project, rustc_host, Execs}; +use cargo_test_support::{paths, project, rustc_host, str, Execs}; use std::path::{Path, PathBuf}; struct Setup { @@ -254,14 +252,22 @@ fn simple_lib_std() { p.cargo("build -v") .build_std(&setup) .target_host() - .with_stderr_contains("[RUNNING] `[..]--crate-name std [..]`") + .with_stderr_data(str![[r#" +... +[RUNNING] `[..] rustc --crate-name std [..]` +... +"#]]) .run(); // Check freshness. p.change_file("src/lib.rs", " "); p.cargo("build -v") .build_std(&setup) .target_host() - .with_stderr_contains("[FRESH] std[..]") + .with_stderr_data(str![[r#" +... +[FRESH] std v0.1.0 ([..]/tests/testsuite/mock-std/library/std) +... +"#]]) .run(); } @@ -273,6 +279,7 @@ fn simple_bin_std() { p.cargo("run -v").build_std(&setup).target_host().run(); } +#[allow(deprecated)] #[cargo_test(build_std_mock)] fn lib_nostd() { let setup = setup(); @@ -306,7 +313,11 @@ fn check_core() { p.cargo("check -v") .build_std_arg(&setup, "core") .target_host() - .with_stderr_contains("[WARNING] [..]unused_fn[..]") + .with_stderr_data(str![[r#" +... +[WARNING] function `unused_fn` is never used +... +"#]]) .run(); } @@ -366,7 +377,14 @@ fn test() { p.cargo("test -v") .build_std(&setup) .target_host() - .with_stdout_contains("test tests::it_works ... ok") + .with_stdout_data(str![[r#" + +running 1 test +test tests::it_works ... ok + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s +... +"#]]) .run(); } @@ -483,7 +501,15 @@ fn doctest() { p.cargo("test --doc -v -Zdoctest-xcompile") .build_std(&setup) - .with_stdout_contains("test src/lib.rs - f [..] ... ok") + .with_stdout_data(str![[r#" + +running 1 test +test src/lib.rs - f (line 3) ... ok + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s + + +"#]]) .target_host() .run(); } @@ -507,7 +533,11 @@ fn no_implicit_alloc() { p.cargo("build -v") .build_std(&setup) .target_host() - .with_stderr_contains("[..]use of undeclared [..]`alloc`") + .with_stderr_data(str![[r#" +... +error[E0433]: failed to resolve: use of undeclared crate or module `alloc` +... +"#]]) .with_status(101) .run(); } @@ -562,6 +592,7 @@ fn ignores_incremental() { .starts_with("foo-")); } +#[allow(deprecated)] #[cargo_test(build_std_mock)] fn cargo_config_injects_compiler_builtins() { let setup = setup(); @@ -622,7 +653,11 @@ fn no_roots() { p.cargo("build") .build_std(&setup) .target_host() - .with_stderr_contains("[FINISHED] [..]") + .with_stderr_data(str![[r#" +... +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -648,10 +683,15 @@ fn proc_macro_only() { p.cargo("build") .build_std(&setup) .target_host() - .with_stderr_contains("[FINISHED] [..]") + .with_stderr_data(str![[r#" +... +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } +#[allow(deprecated)] #[cargo_test(build_std_mock)] fn fetch() { let setup = setup();