Skip to content

Commit c5bc336

Browse files
committed
refactor(test): migrate some tests to .expect() APIs
1 parent 37b4013 commit c5bc336

File tree

4 files changed

+56
-46
lines changed

4 files changed

+56
-46
lines changed

tests/suite/cli_exact.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustup::test::{
88
CROSS_ARCH1, CROSS_ARCH2, CliTestContext, MULTI_ARCH1, Scenario, this_host_triple,
99
};
1010
use rustup::utils::raw;
11+
use snapbox::str;
1112

1213
#[tokio::test]
1314
async fn update_once() {
@@ -311,23 +312,21 @@ info: default toolchain set to 'nightly-{0}'
311312

312313
#[tokio::test]
313314
async fn override_again() {
314-
let mut cx = CliTestContext::new(Scenario::SimpleV2).await;
315-
let cwd = cx.config.current_dir();
315+
let cx = &CliTestContext::new(Scenario::SimpleV2).await;
316316
cx.config
317-
.expect_ok(&["rustup", "override", "add", "nightly"])
318-
.await;
317+
.expect(["rustup", "override", "add", "nightly"])
318+
.await
319+
.is_ok();
319320
cx.config
320-
.expect_ok_ex(
321-
&["rustup", "override", "add", "nightly"],
322-
"",
323-
&format!(
324-
r"info: override toolchain for '{}' set to 'nightly-{1}'
325-
",
326-
cwd.display(),
327-
&this_host_triple()
328-
),
329-
)
330-
.await;
321+
.expect(["rustup", "override", "add", "nightly"])
322+
.await
323+
.extend_redactions([("[CWD]", cx.config.current_dir().display().to_string())])
324+
.is_ok()
325+
.with_stdout("")
326+
.with_stderr(str![[r#"
327+
info: override toolchain for '[CWD]' set to 'nightly-[HOST_TRIPLE]'
328+
329+
"#]]);
331330
}
332331

333332
#[tokio::test]

tests/suite/cli_misc.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use rustup::test::{
1313
};
1414
use rustup::utils;
1515
use rustup::utils::raw::symlink_dir;
16+
use snapbox::str;
1617

1718
#[tokio::test]
1819
async fn smoke_test() {
@@ -115,16 +116,15 @@ async fn custom_invalid_names_with_archive_dates() {
115116
async fn update_all_no_update_whitespace() {
116117
let cx = CliTestContext::new(Scenario::SimpleV2).await;
117118
cx.config
118-
.expect_stdout_ok(
119-
&["rustup", "update", "nightly"],
120-
for_host!(
121-
r"
122-
nightly-{} installed - 1.3.0 (hash-nightly-2)
119+
.expect(["rustup", "update", "nightly"])
120+
.await
121+
.is_ok()
122+
.with_stdout(str![[r#"
123123
124-
"
125-
),
126-
)
127-
.await;
124+
nightly-[HOST_TRIPLE] installed - 1.3.0 (hash-nightly-2)
125+
126+
127+
"#]]);
128128
}
129129

130130
// Issue #145

tests/suite/cli_self_upd.rs

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use rustup::test::{
2222
use rustup::test::{RegistryGuard, RegistryValueId, USER_PATH};
2323
use rustup::utils::{self, raw};
2424
use rustup::{DUP_TOOLS, TOOLS, for_host};
25+
use snapbox::str;
2526
#[cfg(windows)]
2627
use windows_registry::Value;
2728

@@ -390,26 +391,32 @@ info: downloading self-update (new version: {TEST_VERSION})
390391

391392
#[tokio::test]
392393
async fn update_precise() {
393-
let version = env!("CARGO_PKG_VERSION");
394-
let expected_output = format!(
395-
"info: checking for self-update (current version: {version})
396-
info: `RUSTUP_VERSION` has been set to `{TEST_VERSION}`
397-
info: downloading self-update (new version: {TEST_VERSION})
398-
"
399-
);
400-
401-
let mut cx = SelfUpdateTestContext::new(TEST_VERSION).await;
394+
let cx = SelfUpdateTestContext::new(TEST_VERSION).await;
402395
cx.config
403-
.expect_ok(&["rustup-init", "-y", "--no-modify-path"])
404-
.await;
396+
.expect(["rustup-init", "-y", "--no-modify-path"])
397+
.await
398+
.is_ok();
405399
cx.config
406-
.expect_ok_ex_env(
407-
&["rustup", "self", "update"],
408-
&[("RUSTUP_VERSION", TEST_VERSION)],
409-
&format!(" rustup updated - {version} (from {version})\n\n",),
410-
&expected_output,
400+
.expect_with_env(
401+
["rustup", "self", "update"],
402+
[("RUSTUP_VERSION", TEST_VERSION)],
411403
)
412-
.await;
404+
.await
405+
.extend_redactions([
406+
("[TEST_VERSION]", TEST_VERSION),
407+
("[VERSION]", env!("CARGO_PKG_VERSION")),
408+
])
409+
.with_stdout(str![[r#"
410+
rustup updated - [VERSION] (from [VERSION])
411+
412+
413+
"#]])
414+
.with_stderr(str![[r#"
415+
info: checking for self-update (current version: [VERSION])
416+
info: `RUSTUP_VERSION` has been set to `[TEST_VERSION]`
417+
info: downloading self-update (new version: [TEST_VERSION])
418+
419+
"#]]);
413420
}
414421

415422
#[cfg(windows)]

tests/suite/cli_v1.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,20 @@ use std::fs;
77

88
use rustup::for_host;
99
use rustup::test::{CliTestContext, Scenario};
10+
use snapbox::str;
1011

1112
#[tokio::test]
1213
async fn rustc_no_default_toolchain() {
1314
let cx = CliTestContext::new(Scenario::SimpleV1).await;
1415
cx.config
15-
.expect_err(
16-
&["rustc"],
17-
"rustup could not choose a version of rustc to run",
18-
)
19-
.await;
16+
.expect(["rustc"])
17+
.await
18+
.is_err()
19+
.with_stderr(str![[r#"
20+
error: rustup could not choose a version of rustc to run, because one wasn't specified explicitly, and no default is configured.
21+
help: run 'rustup default stable' to download the latest stable release of Rust and set it as your default toolchain.
22+
23+
"#]]);
2024
}
2125

2226
#[tokio::test]

0 commit comments

Comments
 (0)