From: liushuyu <liushuyu011@gmail.com>
Date: Tue, 12 Sep 2023 17:10:31 -0600
Subject: [PATCH 5/7] tests: disable self-update tests
Forwarded: no

---
 src/test.rs               | 13 +++++++++++++
 src/test/mock/clitools.rs |  8 +++++++-
 tests/suite/cli_exact.rs  |  2 ++
 tests/suite/cli_paths.rs  |  3 +++
 tests/suite/cli_v2.rs     |  3 ++-
 5 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/src/test.rs b/src/test.rs
index 617b765..b537bf3 100644
--- a/src/test.rs
+++ b/src/test.rs
@@ -175,6 +175,19 @@ macro_rules! for_host {
     };
 }
 
+#[macro_export]
+macro_rules! get_output_trailer {
+    () => {
+        if cfg!(feature = "no-self-update") {
+            "info: self-update is disabled for this build of rustup
+info: any updates to rustup will need to be fetched with your system package manager
+"
+        } else {
+            "\n"
+        }
+    };
+}
+
 #[derive(Clone, Debug)]
 /// The smallest form of test isolation: an isolated RUSTUP_HOME, for codepaths
 /// that read and write config files but do not invoke processes, download data
diff --git a/src/test/mock/clitools.rs b/src/test/mock/clitools.rs
index efa071e..328aaa7 100644
--- a/src/test/mock/clitools.rs
+++ b/src/test/mock/clitools.rs
@@ -24,6 +24,7 @@ use crate::test as rustup_test;
 use crate::test::const_dist_dir;
 use crate::test::this_host_triple;
 use crate::utils::{raw, utils};
+use crate::get_output_trailer;
 
 use super::{
     dist::{
@@ -335,6 +336,7 @@ fn create_local_update_server(self_dist: &Path, exedir: &Path, version: &str) ->
     root_url
 }
 
+#[cfg(not(feature = "no-self-update"))]
 pub fn self_update_setup(f: &dyn Fn(&mut Config, &Path), version: &str) {
     test(Scenario::SimpleV2, &|config| {
         // Create a mock self-update server
@@ -593,11 +595,15 @@ impl Config {
     #[track_caller]
     pub fn expect_ok_ex(&mut self, args: &[&str], stdout: &str, stderr: &str) {
         let out = self.run(args[0], &args[1..], &[]);
+        let mut stderr = stderr.to_string();
+        if out.stderr != stderr {
+            stderr = format!("{}\n{}", stderr.trim_end(), get_output_trailer!());
+        }
         if !out.ok || out.stdout != stdout || out.stderr != stderr {
             print_command(args, &out);
             println!("expected.ok: true");
             print_indented("expected.stdout", stdout);
-            print_indented("expected.stderr", stderr);
+            print_indented("expected.stderr", &stderr);
             dbg!(out.stdout == stdout);
             dbg!(out.stderr == stderr);
             panic!();
diff --git a/tests/suite/cli_exact.rs b/tests/suite/cli_exact.rs
index fc92c22..51c6435 100644
--- a/tests/suite/cli_exact.rs
+++ b/tests/suite/cli_exact.rs
@@ -45,6 +45,7 @@ info: default toolchain set to 'nightly-{0}'
 }
 
 #[test]
+#[cfg(not(feature = "no-self-update"))]
 fn update_once_and_check_self_update() {
     let test_version = "2.0.0";
     test(&|config| {
@@ -86,6 +87,7 @@ info: installing component 'rustc'
 }
 
 #[test]
+#[cfg(not(feature = "no-self-update"))]
 fn update_once_and_self_update() {
     let test_version = "2.0.0";
 
diff --git a/tests/suite/cli_paths.rs b/tests/suite/cli_paths.rs
index 5911212..896387e 100644
--- a/tests/suite/cli_paths.rs
+++ b/tests/suite/cli_paths.rs
@@ -239,6 +239,7 @@ export PATH="$HOME/apple/bin"
     }
 
     #[test]
+    #[cfg(not(feature = "no-self-update"))]
     fn uninstall_removes_source_from_rcs() {
         clitools::test(Scenario::Empty, &|config| {
             let rcs: Vec<PathBuf> = [
@@ -305,6 +306,7 @@ export PATH="$HOME/apple/bin"
     }
 
     #[test]
+    #[cfg(not(feature = "no-self-update"))]
     fn uninstall_cleans_up_legacy_paths() {
         clitools::test(Scenario::Empty, &|config| {
             // Install first, then overwrite.
@@ -347,6 +349,7 @@ export PATH="$HOME/apple/bin"
     // In the default case we want to write $HOME/.cargo/bin as the path,
     // not the full path.
     #[test]
+    #[cfg(not(feature = "no-self-update"))]
     fn when_cargo_home_is_the_default_write_path_specially() {
         clitools::test(Scenario::Empty, &|config| {
             // Override the test harness so that cargo home looks like
diff --git a/tests/suite/cli_v2.rs b/tests/suite/cli_v2.rs
index 81ba41e..5d1dcf9 100644
--- a/tests/suite/cli_v2.rs
+++ b/tests/suite/cli_v2.rs
@@ -1300,6 +1300,7 @@ fn install_with_component_and_target() {
 }
 
 #[test]
+#[cfg(not(feature = "no-self-update"))]
 fn test_warn_if_complete_profile_is_used() {
     setup(&|config| {
         config.expect_ok(&["rustup", "set", "auto-self-update", "enable"]);
@@ -1312,7 +1313,7 @@ fn test_warn_if_complete_profile_is_used() {
                 "complete",
                 "stable",
             ],
-            "warning: downloading with complete profile",
+            "warning: downloading with complete profile isn't recommended",
         );
     });
 }
