From a67f4edff4cf671053070175f382cf85cee81113 Mon Sep 17 00:00:00 2001 From: Heng-Yi Wu <2316687+henry40408@users.noreply.github.com> Date: Tue, 18 Jun 2024 06:03:42 +0800 Subject: [PATCH 1/5] test: remove deprecated attribute from testsuite death --- tests/testsuite/death.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/testsuite/death.rs b/tests/testsuite/death.rs index 93884cb1236..f9049a8f168 100644 --- a/tests/testsuite/death.rs +++ b/tests/testsuite/death.rs @@ -1,7 +1,5 @@ //! Tests for ctrl-C handling. -#![allow(deprecated)] - use cargo_test_support::{project, slow_cpu_multiplier}; use std::fs; use std::io::{self, Read}; From efbcbb0af7e8e9454fb63618ca5da688b6402a8d Mon Sep 17 00:00:00 2001 From: Heng-Yi Wu <2316687+henry40408@users.noreply.github.com> Date: Tue, 18 Jun 2024 06:27:00 +0800 Subject: [PATCH 2/5] test: migrate testsuite message_format to snapbox This reverts commit 2fbba5300c94237960540e176cdc9b0c829d0022. --- tests/testsuite/message_format.rs | 46 +++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/tests/testsuite/message_format.rs b/tests/testsuite/message_format.rs index 3a1e60d21fe..e7a85f9a44d 100644 --- a/tests/testsuite/message_format.rs +++ b/tests/testsuite/message_format.rs @@ -1,8 +1,6 @@ //! Tests for --message-format flag. -#![allow(deprecated)] - -use cargo_test_support::{basic_lib_manifest, basic_manifest, project}; +use cargo_test_support::{basic_lib_manifest, basic_manifest, project, str}; #[cargo_test] fn cannot_specify_two() { @@ -13,12 +11,14 @@ fn cannot_specify_two() { let formats = ["human", "json", "short"]; - let two_kinds = "error: cannot specify two kinds of `message-format` arguments\n"; for a in formats.iter() { for b in formats.iter() { p.cargo(&format!("build --message-format {},{}", a, b)) .with_status(101) - .with_stderr(two_kinds) + .with_stderr_data(str![[r#" +[ERROR] cannot specify two kinds of `message-format` arguments + +"#]]) .run(); } } @@ -45,6 +45,7 @@ fn double_json_works() { .run(); } +#[allow(deprecated)] #[cargo_test] fn cargo_renders() { let p = project() @@ -89,17 +90,17 @@ fn cargo_renders_short() { p.cargo("check --message-format json-render-diagnostics,json-diagnostic-short") .with_status(101) - .with_stderr_contains( - "\ -[CHECKING] foo [..] -error[..]`main`[..] -", - ) - .with_stderr_does_not_contain("note:") + .with_stderr_data(str![[r#" +[CHECKING] foo v0.1.0 ([ROOT]/foo) +error[E0601]: `main` function not found in crate `foo` +[ERROR] could not compile `foo` (bin "foo") due to 1 previous error + +"#]]) .run(); } #[cargo_test] +#[allow(deprecated)] fn cargo_renders_ansi() { let p = project() .file("Cargo.toml", &basic_manifest("foo", "0.1.0")) @@ -129,7 +130,24 @@ fn cargo_renders_doctests() { p.cargo("test --doc --message-format short") .with_status(101) - .with_stdout_contains("src/lib.rs:2:1: error[E0425]:[..]") - .with_stdout_contains("[..]src/lib.rs - bar (line 1)[..]") + .with_stdout_data(str![[r#" + +running 1 test +test src/lib.rs - bar (line 1) ... FAILED + +failures: + +---- src/lib.rs - bar (line 1) stdout ---- +src/lib.rs:2:1: error[E0425]: cannot find function `bar` in this scope +[ERROR] aborting due to 1 previous error +Couldn't compile the test. + +failures: + src/lib.rs - bar (line 1) + +test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s + + +"#]]) .run(); } From d6024347facdde77e17ed935e5fcb109bdd98b65 Mon Sep 17 00:00:00 2001 From: Heng-Yi Wu <2316687+henry40408@users.noreply.github.com> Date: Tue, 18 Jun 2024 06:14:46 +0800 Subject: [PATCH 3/5] test: migrate testsuite precise_pre_release to snapbox --- tests/testsuite/precise_pre_release.rs | 37 +++++++++++++------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/tests/testsuite/precise_pre_release.rs b/tests/testsuite/precise_pre_release.rs index c3030fe3934..822e537b360 100644 --- a/tests/testsuite/precise_pre_release.rs +++ b/tests/testsuite/precise_pre_release.rs @@ -1,8 +1,6 @@ //! Tests for selecting pre-release versions with `update --precise`. -#![allow(deprecated)] - -use cargo_test_support::project; +use cargo_test_support::{project, str}; #[cargo_test] fn requires_nightly_cargo() { @@ -29,16 +27,17 @@ fn requires_nightly_cargo() { .with_status(101) // This error is suffering from #12579 but still demonstrates that updating to // a pre-release does not work on stable - .with_stderr( - r#"[UPDATING] `dummy-registry` index + .with_stderr_data(str![[r#" +[UPDATING] `dummy-registry` index [ERROR] failed to select a version for the requirement `my-dependency = "^0.1.1"` candidate versions found which didn't match: 0.1.2-pre.0 location searched: `dummy-registry` index (which is replacing registry `crates-io`) required by package `package v0.0.0 ([ROOT]/foo)` if you are looking for the prerelease package it needs to be specified explicitly my-dependency = { version = "0.1.2-pre.0" } -perhaps a crate was updated and forgotten to be re-vendored?"#, - ) +perhaps a crate was updated and forgotten to be re-vendored? + +"#]]) .run() } @@ -65,11 +64,11 @@ fn update_pre_release() { p.cargo("update my-dependency --precise 0.1.2-pre.0 -Zunstable-options") .masquerade_as_nightly_cargo(&["precise-pre-release"]) - .with_stderr( - r#"[UPDATING] `dummy-registry` index + .with_stderr_data(str![[r#" +[UPDATING] `dummy-registry` index [UPDATING] my-dependency v0.1.1 -> v0.1.2-pre.0 -"#, - ) + +"#]]) .run(); let lockfile = p.read_lockfile(); assert!(lockfile.contains("\nname = \"my-dependency\"\nversion = \"0.1.2-pre.0\"")); @@ -98,20 +97,20 @@ fn update_pre_release_differ() { p.cargo("update -p my-dependency --precise 0.1.2-pre.0 -Zunstable-options") .masquerade_as_nightly_cargo(&["precise-pre-release"]) - .with_stderr( - r#"[UPDATING] `dummy-registry` index + .with_stderr_data(str![[r#" +[UPDATING] `dummy-registry` index [DOWNGRADING] my-dependency v0.1.2 -> v0.1.2-pre.0 -"#, - ) + +"#]]) .run(); p.cargo("update -p my-dependency --precise 0.1.2-pre.1 -Zunstable-options") .masquerade_as_nightly_cargo(&["precise-pre-release"]) - .with_stderr( - r#"[UPDATING] `dummy-registry` index + .with_stderr_data(str![[r#" +[UPDATING] `dummy-registry` index [UPDATING] my-dependency v0.1.2-pre.0 -> v0.1.2-pre.1 -"#, - ) + +"#]]) .run(); let lockfile = p.read_lockfile(); From 1e0dca3935168751487f04b7b4eeabc072636a5e Mon Sep 17 00:00:00 2001 From: Heng-Yi Wu <2316687+henry40408@users.noreply.github.com> Date: Tue, 18 Jun 2024 05:53:16 +0800 Subject: [PATCH 4/5] test: migrate testsuite verify_project to snapbox --- tests/testsuite/verify_project.rs | 33 ++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/tests/testsuite/verify_project.rs b/tests/testsuite/verify_project.rs index 4b0450a7a61..974c361173f 100644 --- a/tests/testsuite/verify_project.rs +++ b/tests/testsuite/verify_project.rs @@ -1,12 +1,6 @@ //! Tests for the `cargo verify-project` command. -#![allow(deprecated)] - -use cargo_test_support::{basic_bin_manifest, main_file, project}; - -fn verify_project_success_output() -> String { - r#"{"success":"true"}"#.into() -} +use cargo_test_support::{basic_bin_manifest, main_file, project, str}; #[cargo_test] fn cargo_verify_project_path_to_cargo_toml_relative() { @@ -17,7 +11,10 @@ fn cargo_verify_project_path_to_cargo_toml_relative() { p.cargo("verify-project --manifest-path foo/Cargo.toml") .cwd(p.root().parent().unwrap()) - .with_stdout(verify_project_success_output()) + .with_stdout_data(str![[r#" +{"success":"true"} + +"#]]) .run(); } @@ -31,7 +28,10 @@ fn cargo_verify_project_path_to_cargo_toml_absolute() { p.cargo("verify-project --manifest-path") .arg(p.root().join("Cargo.toml")) .cwd(p.root().parent().unwrap()) - .with_stdout(verify_project_success_output()) + .with_stdout_data(str![[r#" +{"success":"true"} + +"#]]) .run(); } @@ -43,7 +43,10 @@ fn cargo_verify_project_cwd() { .build(); p.cargo("verify-project") - .with_stdout(verify_project_success_output()) + .with_stdout_data(str![[r#" +{"success":"true"} + +"#]]) .run(); } @@ -65,11 +68,17 @@ fn cargo_verify_project_honours_unstable_features() { p.cargo("verify-project") .masquerade_as_nightly_cargo(&["test-dummy-unstable"]) - .with_stdout(verify_project_success_output()) + .with_stdout_data(str![[r#" +{"success":"true"} + +"#]]) .run(); p.cargo("verify-project") .with_status(1) - .with_json(r#"{"invalid":"failed to parse manifest at `[CWD]/Cargo.toml`"}"#) + .with_stdout_data(str![[r#" +{"invalid":"failed to parse manifest at `[..]`"} + +"#]]) .run(); } From 2c517d98588bee9832942572154f6f18b8644074 Mon Sep 17 00:00:00 2001 From: Heng-Yi Wu <2316687+henry40408@users.noreply.github.com> Date: Tue, 18 Jun 2024 05:48:21 +0800 Subject: [PATCH 5/5] test: migrate testsuite version to snapbox --- tests/testsuite/version.rs | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/tests/testsuite/version.rs b/tests/testsuite/version.rs index 008f15db6b9..f9e49a64dda 100644 --- a/tests/testsuite/version.rs +++ b/tests/testsuite/version.rs @@ -1,7 +1,5 @@ //! Tests for displaying the cargo version. -#![allow(deprecated)] - use cargo_test_support::{cargo_process, project}; #[cargo_test] @@ -9,15 +7,15 @@ fn simple() { let p = project().build(); p.cargo("version") - .with_stdout(&format!("cargo {}\n", cargo::version())) + .with_stdout_data(&format!("cargo {}\n", cargo::version())) .run(); p.cargo("--version") - .with_stdout(&format!("cargo {}\n", cargo::version())) + .with_stdout_data(&format!("cargo {}\n", cargo::version())) .run(); p.cargo("-V") - .with_stdout(&format!("cargo {}\n", cargo::version())) + .with_stdout_data(&format!("cargo {}\n", cargo::version())) .run(); } @@ -53,10 +51,19 @@ fn version_works_with_bad_target_dir() { fn verbose() { // This is mainly to check that it doesn't explode. cargo_process("-vV") - .with_stdout_contains(&format!("cargo {}", cargo::version())) - .with_stdout_contains("host: [..]") - .with_stdout_contains("libgit2: [..]") - .with_stdout_contains("libcurl: [..]") - .with_stdout_contains("os: [..]") + .with_stdout_data(format!( + "\ +cargo {} +release: [..] +commit-hash: [..] +commit-date: [..] +host: [HOST_TARGET] +libgit2: [..] (sys:[..] [..]) +libcurl: [..] (sys:[..] [..]) +... +os: [..] +", + cargo::version() + )) .run(); }