Skip to content

Commit 5badfb1

Browse files
committed
Auto merge of #5854 - dwijnand:args-split_whitespace, r=alexcrichton
Cleanup tests by using single string commands, split on whitespaces Refs #5742
2 parents dd97d5a + f88ff96 commit 5badfb1

File tree

14 files changed

+245
-546
lines changed

14 files changed

+245
-546
lines changed

tests/testsuite/cargo_command.rs

Lines changed: 27 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@ fn list_command_looks_at_path() {
8787
"cargo-1",
8888
&FakeKind::Executable,
8989
);
90-
let mut pr = cargo_process();
9190

9291
let mut path = path();
9392
path.push(proj.root().join("path-test"));
9493
let path = env::join_paths(path.iter()).unwrap();
95-
let output = pr.arg("-v").arg("--list").env("PATH", &path);
94+
let mut p = cargo_process("-v --list");
95+
let output = p.env("PATH", &path);
9696
let output = output.exec_with_output().unwrap();
9797
let output = str::from_utf8(&output.stdout).unwrap();
9898
assert!(
@@ -115,12 +115,12 @@ fn list_command_resolves_symlinks() {
115115
target: &cargo_exe(),
116116
},
117117
);
118-
let mut pr = cargo_process();
119118

120119
let mut path = path();
121120
path.push(proj.root().join("path-test"));
122121
let path = env::join_paths(path.iter()).unwrap();
123-
let output = pr.arg("-v").arg("--list").env("PATH", &path);
122+
let mut p = cargo_process("-v --list");
123+
let output = p.env("PATH", &path);
124124
let output = output.exec_with_output().unwrap();
125125
let output = str::from_utf8(&output.stdout).unwrap();
126126
assert!(
@@ -133,7 +133,7 @@ fn list_command_resolves_symlinks() {
133133
#[test]
134134
fn find_closest_biuld_to_build() {
135135
assert_that(
136-
cargo_process().arg("biuld"),
136+
cargo_process("biuld"),
137137
execs().with_status(101).with_stderr_contains(
138138
"\
139139
error: no such subcommand: `biuld`
@@ -157,17 +157,17 @@ error: no such subcommand: `biuld`
157157
.publish();
158158

159159
assert_that(
160-
cargo_process().arg("install").arg("cargo-biuld"),
160+
cargo_process("install cargo-biuld"),
161161
execs().with_status(0),
162162
);
163163
assert_that(
164-
cargo_process().arg("biuld"),
164+
cargo_process("biuld"),
165165
execs()
166166
.with_status(0)
167167
.with_stdout("Similar, but not identical to, build\n"),
168168
);
169169
assert_that(
170-
cargo_process().arg("--list"),
170+
cargo_process("--list"),
171171
execs()
172172
.with_status(0)
173173
.with_stdout_contains(" build Compile a local package and all of its dependencies\n")
@@ -178,12 +178,9 @@ error: no such subcommand: `biuld`
178178
// if a subcommand is more than 3 edit distance away, we don't make a suggestion
179179
#[test]
180180
fn find_closest_dont_correct_nonsense() {
181-
let mut pr = cargo_process();
182-
pr.arg("there-is-no-way-that-there-is-a-command-close-to-this")
183-
.cwd(&paths::root());
184-
185181
assert_that(
186-
pr,
182+
cargo_process("there-is-no-way-that-there-is-a-command-close-to-this")
183+
.cwd(&paths::root()),
187184
execs().with_status(101).with_stderr(
188185
"[ERROR] no such subcommand: \
189186
`there-is-no-way-that-there-is-a-command-close-to-this`
@@ -194,15 +191,11 @@ fn find_closest_dont_correct_nonsense() {
194191

195192
#[test]
196193
fn displays_subcommand_on_error() {
197-
let mut pr = cargo_process();
198-
pr.arg("invalid-command");
199-
200194
assert_that(
201-
pr,
202-
execs().with_status(101).with_stderr(
203-
"[ERROR] no such subcommand: `invalid-command`
204-
",
205-
),
195+
cargo_process("invalid-command"),
196+
execs()
197+
.with_status(101)
198+
.with_stderr("[ERROR] no such subcommand: `invalid-command`\n"),
206199
);
207200
}
208201

@@ -224,11 +217,7 @@ fn override_cargo_home() {
224217
.unwrap();
225218

226219
assert_that(
227-
cargo_process()
228-
.arg("new")
229-
.arg("foo")
230-
.env("USER", "foo")
231-
.env("CARGO_HOME", &my_home),
220+
cargo_process("new foo").env("USER", "foo").env("CARGO_HOME", &my_home),
232221
execs().with_status(0),
233222
);
234223

@@ -264,14 +253,13 @@ fn cargo_subcommand_env() {
264253
assert_that(p.cargo("build"), execs().with_status(0));
265254
assert_that(&p.bin("cargo-envtest"), existing_file());
266255

267-
let mut pr = cargo_process();
268256
let cargo = cargo_exe().canonicalize().unwrap();
269257
let mut path = path();
270258
path.push(target_dir);
271259
let path = env::join_paths(path.iter()).unwrap();
272260

273261
assert_that(
274-
pr.arg("envtest").env("PATH", &path),
262+
cargo_process("envtest").env("PATH", &path),
275263
execs().with_status(0).with_stdout(cargo.to_str().unwrap()),
276264
);
277265
}
@@ -300,12 +288,7 @@ fn cargo_subcommand_args() {
300288
let path = env::join_paths(path.iter()).unwrap();
301289

302290
assert_that(
303-
cargo_process()
304-
.env("PATH", &path)
305-
.arg("foo")
306-
.arg("bar")
307-
.arg("-v")
308-
.arg("--help"),
291+
cargo_process("foo bar -v --help").env("PATH", &path),
309292
execs().with_status(0).with_stdout(format!(
310293
r#"[{:?}, "foo", "bar", "-v", "--help"]"#,
311294
cargo_foo_bin
@@ -315,21 +298,12 @@ fn cargo_subcommand_args() {
315298

316299
#[test]
317300
fn cargo_help() {
318-
assert_that(cargo_process(), execs().with_status(0));
319-
assert_that(cargo_process().arg("help"), execs().with_status(0));
320-
assert_that(cargo_process().arg("-h"), execs().with_status(0));
321-
assert_that(
322-
cargo_process().arg("help").arg("build"),
323-
execs().with_status(0),
324-
);
325-
assert_that(
326-
cargo_process().arg("build").arg("-h"),
327-
execs().with_status(0),
328-
);
329-
assert_that(
330-
cargo_process().arg("help").arg("help"),
331-
execs().with_status(0),
332-
);
301+
assert_that(cargo_process(""), execs().with_status(0));
302+
assert_that(cargo_process("help"), execs().with_status(0));
303+
assert_that(cargo_process("-h"), execs().with_status(0));
304+
assert_that(cargo_process("help build"), execs().with_status(0));
305+
assert_that(cargo_process("build -h"), execs().with_status(0));
306+
assert_that(cargo_process("help help"), execs().with_status(0));
333307
}
334308

335309
#[test]
@@ -346,19 +320,19 @@ fn cargo_help_external_subcommand() {
346320
)
347321
.publish();
348322
assert_that(
349-
cargo_process().args(&["install", "cargo-fake-help"]),
323+
cargo_process("install cargo-fake-help"),
350324
execs().with_status(0),
351325
);
352326
assert_that(
353-
cargo_process().args(&["help", "fake-help"]),
327+
cargo_process("help fake-help"),
354328
execs().with_status(0).with_stdout("fancy help output\n")
355329
);
356330
}
357331

358332
#[test]
359333
fn explain() {
360334
assert_that(
361-
cargo_process().arg("--explain").arg("E0001"),
335+
cargo_process("--explain E0001"),
362336
execs().with_status(0).with_stdout_contains(
363337
"This error suggests that the expression arm corresponding to the noted pattern",
364338
),
@@ -370,7 +344,7 @@ fn explain() {
370344
#[test]
371345
fn z_flags_help() {
372346
assert_that(
373-
cargo_process().arg("-Z").arg("help"),
347+
cargo_process("-Z help"),
374348
execs().with_status(0).with_stdout_contains(
375349
" -Z unstable-options -- Allow the usage of unstable options such as --registry",
376350
),

tests/testsuite/concurrent.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::sync::mpsc::channel;
88
use std::time::Duration;
99

1010
use git2;
11-
use support;
11+
use support::cargo_process;
1212
use support::install::{cargo_home, has_installed_exe};
1313
use support::git;
1414
use support::registry::Package;
@@ -57,14 +57,8 @@ fn concurrent_installs() {
5757
pkg("foo", "0.0.1");
5858
pkg("bar", "0.0.1");
5959

60-
let mut a = support::cargo_process()
61-
.arg("install")
62-
.arg("foo")
63-
.build_command();
64-
let mut b = support::cargo_process()
65-
.arg("install")
66-
.arg("bar")
67-
.build_command();
60+
let mut a = cargo_process("install foo").build_command();
61+
let mut b = cargo_process("install bar").build_command();
6862

6963
a.stdout(Stdio::piped()).stderr(Stdio::piped());
7064
b.stdout(Stdio::piped()).stderr(Stdio::piped());

tests/testsuite/directory.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ fn simple_install() {
135135
.build();
136136

137137
assert_that(
138-
cargo_process().arg("install").arg("bar"),
138+
cargo_process("install bar"),
139139
execs().with_status(0).with_stderr(
140140
" Installing bar v0.1.0
141141
Compiling foo v0.0.1
@@ -174,7 +174,7 @@ fn simple_install_fail() {
174174
.build();
175175

176176
assert_that(
177-
cargo_process().arg("install").arg("bar"),
177+
cargo_process("install bar"),
178178
execs().with_status(101).with_stderr(
179179
" Installing bar v0.1.0
180180
error: failed to compile `bar v0.1.0`, intermediate artifacts can be found at `[..]`
@@ -218,7 +218,7 @@ fn install_without_feature_dep() {
218218
.build();
219219

220220
assert_that(
221-
cargo_process().arg("install").arg("bar"),
221+
cargo_process("install bar"),
222222
execs().with_status(0).with_stderr(
223223
" Installing bar v0.1.0
224224
Compiling foo v0.0.1

0 commit comments

Comments
 (0)