diff --git a/Cargo.lock b/Cargo.lock index 8ef451c835..d0e5fcc8d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -406,6 +406,18 @@ dependencies = [ "memchr", ] +[[package]] +name = "console" +version = "0.15.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "054ccb5b10f9f2cbf51eb355ca1d05c2d279ce1804688d0db74b4733a5aeafd8" +dependencies = [ + "encode_unicode", + "libc", + "once_cell", + "windows-sys 0.59.0", +] + [[package]] name = "content_inspector" version = "0.2.4" @@ -599,6 +611,12 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" +[[package]] +name = "encode_unicode" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0" + [[package]] name = "enum-map" version = "2.7.3" @@ -2262,6 +2280,7 @@ dependencies = [ "serde", "sha2", "sharded-slab", + "similar-asserts", "strsim", "tar", "tempfile", @@ -2461,6 +2480,20 @@ name = "similar" version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbbb5d9659141646ae647b42fe094daf6c6192d1620870b449d9557f748b2daa" +dependencies = [ + "bstr", + "unicode-segmentation", +] + +[[package]] +name = "similar-asserts" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b441962c817e33508847a22bd82f03a30cff43642dc2fae8b050566121eb9a" +dependencies = [ + "console", + "similar", +] [[package]] name = "slab" @@ -3055,6 +3088,12 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" +[[package]] +name = "unicode-segmentation" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" + [[package]] name = "untrusted" version = "0.9.0" diff --git a/Cargo.toml b/Cargo.toml index 31005d5652..46223d4168 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,7 @@ otel = [ ] # Exports code dependent on private interfaces for the integration test suite -test = ["dep:walkdir"] +test = ["dep:similar-asserts", "dep:walkdir"] # Sorted by alphabetic order [dependencies] @@ -77,6 +77,7 @@ semver = "1.0" serde = { version = "1.0", features = ["derive"] } sha2 = "0.10" sharded-slab = "0.1.1" +similar-asserts = { version = "1.7", optional = true } # test-only strsim = "0.11" tar = "0.4.26" tempfile = "3.8" diff --git a/src/cli/self_update.rs b/src/cli/self_update.rs index d01b0295ec..255b1f1054 100644 --- a/src/cli/self_update.rs +++ b/src/cli/self_update.rs @@ -1138,7 +1138,7 @@ pub(crate) async fn prepare_update(process: &Process) -> Result> let current_version = env!("CARGO_PKG_VERSION"); // Get available version - info!("checking for self-update"); + info!("checking for self-update (current version: {current_version})"); let available_version = if let Some(ver) = non_empty_env_var("RUSTUP_VERSION", process)? { info!("`RUSTUP_VERSION` has been set to `{ver}`"); ver @@ -1158,7 +1158,7 @@ pub(crate) async fn prepare_update(process: &Process) -> Result> let download_url = utils::parse_url(&url)?; // Download new version - info!("downloading self-update"); + info!("downloading self-update (new version: {available_version})"); download_file(&download_url, &setup_path, None, &|_| (), process).await?; // Mark as executable diff --git a/src/test/clitools.rs b/src/test/clitools.rs index 30518e2517..269f16b8ca 100644 --- a/src/test/clitools.rs +++ b/src/test/clitools.rs @@ -18,6 +18,7 @@ use std::{ }; use enum_map::{Enum, EnumMap, enum_map}; +use similar_asserts::SimpleDiff; use tempfile::TempDir; use url::Url; @@ -236,12 +237,14 @@ impl Config { let out = self.run(args[0], &args[1..], env).await; 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); - dbg!(out.stdout == stdout); - dbg!(out.stderr == stderr); - panic!(); + print_diff(stdout, &out.stdout); + print_diff(stderr, &out.stderr); + panic!( + "expected OK, differences found: ok = {}, stdout = {}, stderr = {}", + out.ok, + out.stdout == stdout, + out.stderr == stderr + ); } } @@ -250,18 +253,14 @@ impl Config { let out = self.run(args[0], &args[1..], &[]).await; if out.ok || out.stdout != stdout || out.stderr != stderr { print_command(args, &out); - println!("expected.ok: false"); - print_indented("expected.stdout", stdout); - print_indented("expected.stderr", stderr); - if out.ok { - panic!("expected command to fail"); - } else if out.stdout != stdout { - panic!("expected stdout to match"); - } else if out.stderr != stderr { - panic!("expected stderr to match"); - } else { - unreachable!() - } + print_diff(stdout, &out.stdout); + print_diff(stderr, &out.stderr); + panic!( + "expected error, differences found: ok = {}, stdout = {}, stderr = {}", + out.ok, + out.stdout == stdout, + out.stderr == stderr + ); } } @@ -430,6 +429,17 @@ impl Config { } } +fn print_diff(expected: &str, actual: &str) { + if expected == actual { + return; + } + + println!( + "{}", + SimpleDiff::from_str(expected, actual, "expected", "actual") + ); +} + // Describes all the features of the mock dist server. // Building the mock server is slow, so use simple scenario when possible. #[derive(Copy, Clone, Debug, Eq, PartialEq, Enum)] diff --git a/tests/suite/cli_exact.rs b/tests/suite/cli_exact.rs index 56e50b3161..0983e55213 100644 --- a/tests/suite/cli_exact.rs +++ b/tests/suite/cli_exact.rs @@ -83,6 +83,7 @@ info: installing component 'rustc' #[tokio::test] async fn update_once_and_self_update() { let test_version = "2.0.0"; + let current = env!("CARGO_PKG_VERSION"); let mut cx = CliTestContext::new(Scenario::SimpleV2).await; let _dist_guard = cx.with_update_server(test_version); cx.config @@ -111,8 +112,8 @@ info: installing component 'cargo' info: installing component 'rust-docs' info: installing component 'rust-std' info: installing component 'rustc' -info: checking for self-update -info: downloading self-update +info: checking for self-update (current version: {current}) +info: downloading self-update (new version: 2.0.0) " ), ) diff --git a/tests/suite/cli_self_upd.rs b/tests/suite/cli_self_upd.rs index b3cd21a0e9..abc55d2690 100644 --- a/tests/suite/cli_self_upd.rs +++ b/tests/suite/cli_self_upd.rs @@ -367,10 +367,11 @@ struct GcErr(Vec); #[tokio::test] async fn update_exact() { let version = env!("CARGO_PKG_VERSION"); - let expected_output = "info: checking for self-update -info: downloading self-update + let expected_output = format!( + "info: checking for self-update (current version: {version}) +info: downloading self-update (new version: {TEST_VERSION}) " - .to_string(); + ); let mut cx = SelfUpdateTestContext::new(TEST_VERSION).await; cx.config @@ -391,7 +392,7 @@ async fn update_precise() { let expected_output = format!( "info: checking for self-update info: `RUSTUP_VERSION` has been set to `{TEST_VERSION}` -info: downloading self-update +info: downloading self-update (new version: {TEST_VERSION}) " ); @@ -563,7 +564,7 @@ async fn update_no_change() { " ), - r"info: checking for self-update + r"info: checking for self-update (current version: {version}) ", ) .await; @@ -647,8 +648,8 @@ async fn rustup_self_update_exact() { ), for_host!( r"info: syncing channel updates for 'stable-{0}' -info: checking for self-update -info: downloading self-update +info: checking for self-update (current version: {TEST_VERSION}) +info: downloading self-update (new version: {TEST_VERSION}) info: cleaning up downloads & tmp directories " ),