From 7c28d80d373c834ec357f8e2344e58d89449f7c4 Mon Sep 17 00:00:00 2001 From: Lawrence Chou Date: Thu, 13 Jun 2024 23:37:23 +0800 Subject: [PATCH 1/7] test: migrate help to snapbox --- tests/testsuite/help.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/tests/testsuite/help.rs b/tests/testsuite/help.rs index 5edb0879805..c7ed744ee47 100644 --- a/tests/testsuite/help.rs +++ b/tests/testsuite/help.rs @@ -1,7 +1,5 @@ //! Tests for cargo's help output. -#![allow(deprecated)] - use cargo_test_support::registry::Package; use cargo_test_support::{basic_manifest, cargo_exe, cargo_process, paths, process, project}; use std::fs; @@ -17,9 +15,15 @@ fn help() { cargo_process("build -h").run(); cargo_process("help help").run(); // Ensure that help output goes to stdout, not stderr. - cargo_process("search --help").with_stderr("").run(); + cargo_process("search --help").with_stderr_data("").run(); cargo_process("search --help") - .with_stdout_contains("[..] --frozen [..]") + .with_stdout_data( + "\ +... +[..] --frozen [..] +... +", + ) .run(); } @@ -41,7 +45,7 @@ fn help_external_subcommand() { .publish(); cargo_process("install cargo-fake-help").run(); cargo_process("help fake-help") - .with_stdout("fancy help output\n") + .with_stdout_data("fancy help output\n") .run(); } @@ -147,7 +151,7 @@ fn help_alias() { // The `empty-alias` returns an error. cargo_process("help empty-alias") .env("PATH", Path::new("")) - .with_stderr_contains("[..]The subcommand 'empty-alias' wasn't recognized[..]") + .with_stderr_data("[..] The subcommand 'empty-alias' wasn't recognized [..]") .run_expect_error(); // Because `simple-alias` aliases a subcommand with no arguments, help shows the manpage. @@ -162,8 +166,12 @@ fn help_alias() { fn alias_z_flag_help() { for cmd in ["build", "run", "check", "test", "b", "r", "c", "t"] { cargo_process(&format!("{cmd} -Z help")) - .with_stdout_contains( - " -Z allow-features[..] Allow *only* the listed unstable features", + .with_stdout_data( + "\ +... + -Z allow-features[..] Allow *only* the listed unstable features +... +", ) .run(); } From 715cba9189956da75cc335d4c4ae000b31bbc956 Mon Sep 17 00:00:00 2001 From: Lawrence Chou Date: Sat, 15 Jun 2024 14:36:42 +0800 Subject: [PATCH 2/7] Tmp commit prior to `SNAPSHOTS=overwrite cargo t --test testsuite help::` # Conflicts: # tests/testsuite/help.rs --- tests/testsuite/help.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/tests/testsuite/help.rs b/tests/testsuite/help.rs index c7ed744ee47..ac59bc04352 100644 --- a/tests/testsuite/help.rs +++ b/tests/testsuite/help.rs @@ -1,6 +1,7 @@ //! Tests for cargo's help output. use cargo_test_support::registry::Package; +use cargo_test_support::str; use cargo_test_support::{basic_manifest, cargo_exe, cargo_process, paths, process, project}; use std::fs; use std::path::Path; @@ -15,15 +16,11 @@ fn help() { cargo_process("build -h").run(); cargo_process("help help").run(); // Ensure that help output goes to stdout, not stderr. - cargo_process("search --help").with_stderr_data("").run(); + cargo_process("search --help").with_stderr(str![]).run(); cargo_process("search --help") - .with_stdout_data( - "\ -... -[..] --frozen [..] -... -", - ) + .with_stdout_contains(str![[r#" +HEY SNAPBOX, FIX THIS AUTOMATICALLY PLEASE +"#]]) .run(); } From 3a95c7846d6102e7fd0f28ac3924148b84528fa6 Mon Sep 17 00:00:00 2001 From: Lawrence Chou Date: Sat, 15 Jun 2024 14:49:57 +0800 Subject: [PATCH 3/7] Revert "Tmp commit prior to `SNAPSHOTS=overwrite cargo t --test testsuite help::`" This reverts commit cbaa4a89e60507366401ac0076d652f5eafc4998. --- tests/testsuite/help.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/testsuite/help.rs b/tests/testsuite/help.rs index ac59bc04352..a7ceee1dc7a 100644 --- a/tests/testsuite/help.rs +++ b/tests/testsuite/help.rs @@ -1,7 +1,6 @@ //! Tests for cargo's help output. use cargo_test_support::registry::Package; -use cargo_test_support::str; use cargo_test_support::{basic_manifest, cargo_exe, cargo_process, paths, process, project}; use std::fs; use std::path::Path; @@ -16,11 +15,9 @@ fn help() { cargo_process("build -h").run(); cargo_process("help help").run(); // Ensure that help output goes to stdout, not stderr. - cargo_process("search --help").with_stderr(str![]).run(); + cargo_process("search --help").with_stderr("").run(); cargo_process("search --help") - .with_stdout_contains(str![[r#" -HEY SNAPBOX, FIX THIS AUTOMATICALLY PLEASE -"#]]) + .with_stdout_contains("[..] --frozen [..]") .run(); } From 3fd3879bc8def6fbb8ba32a89c2cbc70dd1e25c8 Mon Sep 17 00:00:00 2001 From: Lawrence Chou Date: Sat, 15 Jun 2024 14:56:38 +0800 Subject: [PATCH 4/7] Dedup with `cargo::z_help::case` (https://github.com/rust-lang/cargo/pull/14060#discussion_r1638481972) # Conflicts: # tests/testsuite/help.rs --- tests/testsuite/help.rs | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/tests/testsuite/help.rs b/tests/testsuite/help.rs index a7ceee1dc7a..45659f254ed 100644 --- a/tests/testsuite/help.rs +++ b/tests/testsuite/help.rs @@ -155,18 +155,3 @@ fn help_alias() { let out = help_with_stdout_and_path("complex-alias", Path::new("")); assert_eq!(out, "`complex-alias` is aliased to `build --release`\n"); } - -#[cargo_test] -fn alias_z_flag_help() { - for cmd in ["build", "run", "check", "test", "b", "r", "c", "t"] { - cargo_process(&format!("{cmd} -Z help")) - .with_stdout_data( - "\ -... - -Z allow-features[..] Allow *only* the listed unstable features -... -", - ) - .run(); - } -} From eef057ea0f433bf89f5e107747a83a84133d9d54 Mon Sep 17 00:00:00 2001 From: Lawrence Chou Date: Sat, 15 Jun 2024 15:00:01 +0800 Subject: [PATCH 5/7] Dedup with `cargo_search::help::case` (https://github.com/rust-lang/cargo/pull/14060#discussion_r1638479136) --- tests/testsuite/help.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/testsuite/help.rs b/tests/testsuite/help.rs index 45659f254ed..47f0e2b9cad 100644 --- a/tests/testsuite/help.rs +++ b/tests/testsuite/help.rs @@ -14,11 +14,6 @@ fn help() { cargo_process("help build").run(); cargo_process("build -h").run(); cargo_process("help help").run(); - // Ensure that help output goes to stdout, not stderr. - cargo_process("search --help").with_stderr("").run(); - cargo_process("search --help") - .with_stdout_contains("[..] --frozen [..]") - .run(); } #[cargo_test] From e5e9f2f7c5bdd50515a43a378d352a983a76192e Mon Sep 17 00:00:00 2001 From: Lawrence Chou Date: Sat, 15 Jun 2024 15:32:18 +0800 Subject: [PATCH 6/7] Remove `[..]` and mention #14076 caveat --- tests/testsuite/help.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/testsuite/help.rs b/tests/testsuite/help.rs index 47f0e2b9cad..e3ee00963fa 100644 --- a/tests/testsuite/help.rs +++ b/tests/testsuite/help.rs @@ -140,7 +140,11 @@ fn help_alias() { // The `empty-alias` returns an error. cargo_process("help empty-alias") .env("PATH", Path::new("")) - .with_stderr_data("[..] The subcommand 'empty-alias' wasn't recognized [..]") + .with_stderr_data("The subcommand 'empty-alias' wasn't recognized + +FIXME: #14076 This assertion isn't working, as this line should have caused a test failure but didn't. + ", + ) .run_expect_error(); // Because `simple-alias` aliases a subcommand with no arguments, help shows the manpage. From 8db30bc4bdd67de9947f1f9a5dd653edcc2c8d59 Mon Sep 17 00:00:00 2001 From: Lawrence Chou Date: Sat, 15 Jun 2024 22:43:11 +0800 Subject: [PATCH 7/7] Use snapshot generated by `SNAPSHOTS=overwrite cargo test` --- tests/testsuite/help.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/tests/testsuite/help.rs b/tests/testsuite/help.rs index e3ee00963fa..801de16a586 100644 --- a/tests/testsuite/help.rs +++ b/tests/testsuite/help.rs @@ -1,6 +1,7 @@ //! Tests for cargo's help output. use cargo_test_support::registry::Package; +use cargo_test_support::str; use cargo_test_support::{basic_manifest, cargo_exe, cargo_process, paths, process, project}; use std::fs; use std::path::Path; @@ -34,7 +35,10 @@ fn help_external_subcommand() { .publish(); cargo_process("install cargo-fake-help").run(); cargo_process("help fake-help") - .with_stdout_data("fancy help output\n") + .with_stdout_data(str![[r#" +fancy help output + +"#]]) .run(); } @@ -140,12 +144,17 @@ fn help_alias() { // The `empty-alias` returns an error. cargo_process("help empty-alias") .env("PATH", Path::new("")) - .with_stderr_data("The subcommand 'empty-alias' wasn't recognized + .with_status(101) + .with_stderr_data(str![[r#" +[ERROR] no such command: `empty-alias` -FIXME: #14076 This assertion isn't working, as this line should have caused a test failure but didn't. - ", - ) - .run_expect_error(); + Did you mean `empty-alias`? + + View all installed commands with `cargo --list` + Find a package to install `empty-alias` with `cargo search cargo-empty-alias` + +"#]]) + .run(); // Because `simple-alias` aliases a subcommand with no arguments, help shows the manpage. help_with_man_and_path("", "simple-alias", "build", Path::new(""));