Skip to content

Commit b23b07f

Browse files
committed
fixup! refactor(test): add new testing APIs and simple showcases
1 parent 6cfaa62 commit b23b07f

9 files changed

+43
-0
lines changed

src/test/clitools.rs

+35
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,30 @@ impl Assert {
108108
self
109109
}
110110

111+
/// Asserts that the command exited without the given `unexpected` stdout pattern.
112+
pub fn without_stdout(&self, unexpected: &str) -> &Self {
113+
if self.output.stdout.contains(unexpected) {
114+
print_indented("expected.stdout.does_not_contain", unexpected);
115+
panic!();
116+
}
117+
self
118+
}
119+
111120
/// Asserts that the command exited with the given `expected` stderr pattern.
112121
pub fn with_stderr(&self, expected: impl IntoData) -> &Self {
113122
let stderr = self.redactions.redact(&self.output.stderr);
114123
assert_data_eq!(&stderr, expected);
115124
self
116125
}
126+
127+
/// Asserts that the command exited without the given `unexpected` stderr pattern.
128+
pub fn without_stderr(&self, unexpected: &str) -> &Self {
129+
if self.output.stderr.contains(unexpected) {
130+
print_indented("expected.stderr.does_not_contain", unexpected);
131+
panic!();
132+
}
133+
self
134+
}
117135
}
118136

119137
impl Config {
@@ -212,11 +230,14 @@ impl Config {
212230
}
213231

214232
/// Expect an ok status
233+
#[deprecated(note = "use `.expect().await.is_ok()` instead")]
234+
#[allow(deprecated)]
215235
pub async fn expect_ok(&mut self, args: &[&str]) {
216236
self.expect_ok_env(args, &[]).await
217237
}
218238

219239
/// Expect an ok status with extra environment variables
240+
#[deprecated(note = "use `.expect_with_env().await.is_ok()` instead")]
220241
pub async fn expect_ok_env(&self, args: &[&str], env: &[(&str, &str)]) {
221242
let out = self.run(args[0], &args[1..], env).await;
222243
if !out.ok {
@@ -227,11 +248,14 @@ impl Config {
227248
}
228249

229250
/// Expect an err status and a string in stderr
251+
#[deprecated(note = "use `.expect().await.is_err()` instead")]
252+
#[allow(deprecated)]
230253
pub async fn expect_err(&self, args: &[&str], expected: &str) {
231254
self.expect_err_env(args, &[], expected).await
232255
}
233256

234257
/// Expect an err status and a string in stderr, with extra environment variables
258+
#[deprecated(note = "use `.expect_with_env().await.is_err()` instead")]
235259
pub async fn expect_err_env(&self, args: &[&str], env: &[(&str, &str)], expected: &str) {
236260
let out = self.run(args[0], &args[1..], env).await;
237261
if out.ok || !out.stderr.contains(expected) {
@@ -243,6 +267,7 @@ impl Config {
243267
}
244268

245269
/// Expect an ok status and a string in stdout
270+
#[deprecated(note = "use `.expect().await.is_ok().with_stdout()` instead")]
246271
pub async fn expect_stdout_ok(&self, args: &[&str], expected: &str) {
247272
let out = self.run(args[0], &args[1..], &[]).await;
248273
if !out.ok || !out.stdout.contains(expected) {
@@ -253,6 +278,7 @@ impl Config {
253278
}
254279
}
255280

281+
#[deprecated(note = "use `.expect().await.is_ok().without_stdout()` instead")]
256282
pub async fn expect_not_stdout_ok(&self, args: &[&str], expected: &str) {
257283
let out = self.run(args[0], &args[1..], &[]).await;
258284
if !out.ok || out.stdout.contains(expected) {
@@ -263,6 +289,7 @@ impl Config {
263289
}
264290
}
265291

292+
#[deprecated(note = "use `.expect().await.is_ok().without_stderr()` instead")]
266293
pub async fn expect_not_stderr_ok(&self, args: &[&str], expected: &str) {
267294
let out = self.run(args[0], &args[1..], &[]).await;
268295
if !out.ok || out.stderr.contains(expected) {
@@ -273,6 +300,7 @@ impl Config {
273300
}
274301
}
275302

303+
#[deprecated(note = "use `.expect().await.is_err().without_stderr()` instead")]
276304
pub async fn expect_not_stderr_err(&self, args: &[&str], expected: &str) {
277305
let out = self.run(args[0], &args[1..], &[]).await;
278306
if out.ok || out.stderr.contains(expected) {
@@ -284,6 +312,7 @@ impl Config {
284312
}
285313

286314
/// Expect an ok status and a string in stderr
315+
#[deprecated(note = "use `.expect().await.is_ok().with_stderr()` instead")]
287316
pub async fn expect_stderr_ok(&self, args: &[&str], expected: &str) {
288317
let out = self.run(args[0], &args[1..], &[]).await;
289318
if !out.ok || !out.stderr.contains(expected) {
@@ -295,12 +324,17 @@ impl Config {
295324
}
296325

297326
/// Expect an exact strings on stdout/stderr with an ok status code
327+
#[deprecated(note = "use `.expect().await.is_ok().with_stderr()` instead")]
328+
#[allow(deprecated)]
298329
pub async fn expect_ok_ex(&mut self, args: &[&str], stdout: &str, stderr: &str) {
299330
self.expect_ok_ex_env(args, &[], stdout, stderr).await;
300331
}
301332

302333
/// Expect an exact strings on stdout/stderr with an ok status code,
303334
/// with extra environment variables
335+
#[deprecated(
336+
note = "use `.expect_with_env().await.is_ok().with_stdout().with_stderr()` instead"
337+
)]
304338
pub async fn expect_ok_ex_env(
305339
&mut self,
306340
args: &[&str],
@@ -321,6 +355,7 @@ impl Config {
321355
}
322356

323357
/// Expect an exact strings on stdout/stderr with an error status code
358+
#[deprecated(note = "use `.expect().await.is_err().with_stdout().with_stderr()` instead")]
324359
pub async fn expect_err_ex(&self, args: &[&str], stdout: &str, stderr: &str) {
325360
let out = self.run(args[0], &args[1..], &[]).await;
326361
if out.ok || out.stdout != stdout || out.stderr != stderr {

tests/suite/cli_exact.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(deprecated)]
12
//! Yet more cli test cases. These are testing that the output
23
//! is exactly as expected.
34

tests/suite/cli_inst_interactive.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(deprecated)]
12
//! Tests of the interactive console installer
23
34
use std::env::consts::EXE_SUFFIX;

tests/suite/cli_misc.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(deprecated)]
12
//! Test cases of the rustup command that do not depend on the
23
//! dist server, mostly derived from multirust/test-v2.sh
34

tests/suite/cli_paths.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(deprecated)]
12
//! This file contains tests relevant to Rustup's handling of updating PATHs.
23
//! It depends on self-update working, so if absolutely everything here breaks,
34
//! check those tests as well.

tests/suite/cli_rustup.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(deprecated)]
12
//! Test cases for new rustup UI
23
34
use std::fs;

tests/suite/cli_self_upd.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(deprecated)]
12
//! Testing self install, uninstall and update
23
34
use std::env;

tests/suite/cli_v1.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(deprecated)]
12
//! Test cases of the rustup command, using v1 manifests, mostly
23
//! derived from multirust/test-v2.sh
34

tests/suite/cli_v2.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(deprecated)]
12
//! Test cases of the rustup command, using v2 manifests, mostly
23
//! derived from multirust/test-v2.sh
34

0 commit comments

Comments
 (0)