Skip to content

Commit 254f543

Browse files
committed
refactor(test): migrate some tests to .expect() APIs
1 parent 3b1d84e commit 254f543

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
@@ -7,6 +7,7 @@ use rustup::test::{
77
CROSS_ARCH1, CROSS_ARCH2, CliTestContext, MULTI_ARCH1, Scenario, this_host_triple,
88
};
99
use rustup::utils::raw;
10+
use snapbox::str;
1011

1112
#[tokio::test]
1213
async fn update_once() {
@@ -309,23 +310,21 @@ info: default toolchain set to 'nightly-{0}'
309310

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

331330
#[tokio::test]

tests/suite/cli_misc.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use rustup::test::{
1212
};
1313
use rustup::utils;
1414
use rustup::utils::raw::symlink_dir;
15+
use snapbox::str;
1516

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

129129
// Issue #145

tests/suite/cli_self_upd.rs

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

@@ -388,26 +389,32 @@ info: downloading self-update
388389

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

413420
#[cfg(windows)]

tests/suite/cli_v1.rs

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

77
use rustup::for_host;
88
use rustup::test::{CliTestContext, Scenario};
9+
use snapbox::str;
910

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

2125
#[tokio::test]

0 commit comments

Comments
 (0)