Skip to content

Commit 81848c3

Browse files
authored
test: Switch from 'exec_with_output' to 'run' (#14848)
### What does this PR try to resolve? This is a follow up to #14846 which changed `run` to return the `RawOutput`. Reasons I didn't "update" some code to the new `run` return value - We were actually using `ProcessBuilder::exec_with_output` and I didn't want to disentangle what it would take to switch to `Execs` - We did processing on the `Result` and I didn't want to check how that could be updated ### How should we test and review this PR? ### Additional information
2 parents dfcfa44 + 55350fc commit 81848c3

14 files changed

+42
-116
lines changed

tests/testsuite/build.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5452,9 +5452,7 @@ fn same_metadata_different_directory() {
54525452
.file("Cargo.toml", &basic_bin_manifest("foo"))
54535453
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
54545454
.build();
5455-
let output = t!(String::from_utf8(
5456-
t!(p.cargo("build -v").exec_with_output()).stderr,
5457-
));
5455+
let output = t!(String::from_utf8(p.cargo("build -v").run().stderr,));
54585456
let metadata = output
54595457
.split_whitespace()
54605458
.find(|arg| arg.starts_with("metadata="))

tests/testsuite/cache_messages.rs

Lines changed: 12 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,11 @@ fn simple() {
2929
let rustc_output = raw_rustc_output(&p, "src/lib.rs", &[]);
3030

3131
// -q so the output is the same as rustc (no "Compiling" or "Finished").
32-
let cargo_output1 = p
33-
.cargo("check -q --color=never")
34-
.exec_with_output()
35-
.expect("cargo to run");
32+
let cargo_output1 = p.cargo("check -q --color=never").run();
3633
assert_eq!(rustc_output, as_str(&cargo_output1.stderr));
3734
assert!(cargo_output1.stdout.is_empty());
3835
// Check that the cached version is exactly the same.
39-
let cargo_output2 = p
40-
.cargo("check -q")
41-
.exec_with_output()
42-
.expect("cargo to run");
36+
let cargo_output2 = p.cargo("check -q").run();
4337
assert_eq!(rustc_output, as_str(&cargo_output2.stderr));
4438
assert!(cargo_output2.stdout.is_empty());
4539
}
@@ -61,14 +55,10 @@ fn simple_short() {
6155

6256
let cargo_output1 = p
6357
.cargo("check -q --color=never --message-format=short")
64-
.exec_with_output()
65-
.expect("cargo to run");
58+
.run();
6659
assert_eq!(rustc_output, as_str(&cargo_output1.stderr));
6760
// assert!(cargo_output1.stdout.is_empty());
68-
let cargo_output2 = p
69-
.cargo("check -q --message-format=short")
70-
.exec_with_output()
71-
.expect("cargo to run");
61+
let cargo_output2 = p.cargo("check -q --message-format=short").run();
7262
println!("{}", String::from_utf8_lossy(&cargo_output2.stdout));
7363
assert_eq!(rustc_output, as_str(&cargo_output2.stderr));
7464
assert!(cargo_output2.stdout.is_empty());
@@ -102,24 +92,15 @@ fn color() {
10292
assert!(!rustc_nocolor.contains("\x1b["));
10393

10494
// First pass, non-cached, with color, should be the same.
105-
let cargo_output1 = p
106-
.cargo("check -q --color=always")
107-
.exec_with_output()
108-
.expect("cargo to run");
95+
let cargo_output1 = p.cargo("check -q --color=always").run();
10996
compare(&rustc_color, as_str(&cargo_output1.stderr));
11097

11198
// Replay cached, with color.
112-
let cargo_output2 = p
113-
.cargo("check -q --color=always")
114-
.exec_with_output()
115-
.expect("cargo to run");
99+
let cargo_output2 = p.cargo("check -q --color=always").run();
116100
compare(&rustc_color, as_str(&cargo_output2.stderr));
117101

118102
// Replay cached, no color.
119-
let cargo_output_nocolor = p
120-
.cargo("check -q --color=never")
121-
.exec_with_output()
122-
.expect("cargo to run");
103+
let cargo_output_nocolor = p.cargo("check -q --color=never").run();
123104
compare(&rustc_nocolor, as_str(&cargo_output_nocolor.stderr));
124105
}
125106

@@ -130,27 +111,17 @@ fn cached_as_json() {
130111

131112
// Grab the non-cached output, feature disabled.
132113
// NOTE: When stabilizing, this will need to be redone.
133-
let cargo_output = p
134-
.cargo("check --message-format=json")
135-
.exec_with_output()
136-
.expect("cargo to run");
137-
assert!(cargo_output.status.success());
114+
let cargo_output = p.cargo("check --message-format=json").run();
138115
let orig_cargo_out = as_str(&cargo_output.stdout);
139116
assert!(orig_cargo_out.contains("compiler-message"));
140117
p.cargo("clean").run();
141118

142119
// Check JSON output, not fresh.
143-
let cargo_output1 = p
144-
.cargo("check --message-format=json")
145-
.exec_with_output()
146-
.expect("cargo to run");
120+
let cargo_output1 = p.cargo("check --message-format=json").run();
147121
assert_eq!(as_str(&cargo_output1.stdout), orig_cargo_out);
148122

149123
// Check JSON output, fresh.
150-
let cargo_output2 = p
151-
.cargo("check --message-format=json")
152-
.exec_with_output()
153-
.expect("cargo to run");
124+
let cargo_output2 = p.cargo("check --message-format=json").run();
154125
// The only difference should be this field.
155126
let fix_fresh = as_str(&cargo_output2.stdout).replace("\"fresh\":true", "\"fresh\":false");
156127
assert_eq!(fix_fresh, orig_cargo_out);
@@ -220,11 +191,7 @@ fn rustdoc() {
220191
)
221192
.build();
222193

223-
let rustdoc_output = p
224-
.cargo("doc -q --color=always")
225-
.exec_with_output()
226-
.expect("rustdoc to run");
227-
assert!(rustdoc_output.status.success());
194+
let rustdoc_output = p.cargo("doc -q --color=always").run();
228195
let rustdoc_stderr = as_str(&rustdoc_output.stderr);
229196
assert!(rustdoc_stderr.contains("missing"));
230197
assert!(rustdoc_stderr.contains("\x1b["));
@@ -234,10 +201,7 @@ fn rustdoc() {
234201
);
235202

236203
// Check the cached output.
237-
let rustdoc_output = p
238-
.cargo("doc -q --color=always")
239-
.exec_with_output()
240-
.expect("rustdoc to run");
204+
let rustdoc_output = p.cargo("doc -q --color=always").run();
241205
assert_eq!(as_str(&rustdoc_output.stderr), rustdoc_stderr);
242206
}
243207

tests/testsuite/cargo_command.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,7 @@ fn list_command_looks_at_path() {
9999
let mut path = path();
100100
path.push(proj.root().join("path-test"));
101101
let path = env::join_paths(path.iter()).unwrap();
102-
let output = cargo_process("-v --list")
103-
.env("PATH", &path)
104-
.exec_with_output()
105-
.unwrap();
102+
let output = cargo_process("-v --list").env("PATH", &path).run();
106103
let output = str::from_utf8(&output.stdout).unwrap();
107104
assert!(
108105
output.contains("\n 1 "),
@@ -127,8 +124,7 @@ fn list_command_looks_at_path_case_mismatch() {
127124
let output = cargo_process("-v --list")
128125
.env("Path", &path)
129126
.env_remove("PATH")
130-
.exec_with_output()
131-
.unwrap();
127+
.run();
132128
let output = str::from_utf8(&output.stdout).unwrap();
133129
assert!(
134130
output.contains("\n 1 "),
@@ -174,10 +170,7 @@ fn list_command_resolves_symlinks() {
174170
let mut path = path();
175171
path.push(proj.root().join("path-test"));
176172
let path = env::join_paths(path.iter()).unwrap();
177-
let output = cargo_process("-v --list")
178-
.env("PATH", &path)
179-
.exec_with_output()
180-
.unwrap();
173+
let output = cargo_process("-v --list").env("PATH", &path).run();
181174
let output = str::from_utf8(&output.stdout).unwrap();
182175
assert!(
183176
output.contains("\n 2 "),

tests/testsuite/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,7 @@ fn pkgid_querystring_works() {
16481648

16491649
p.cargo("generate-lockfile").run();
16501650

1651-
let output = p.cargo("pkgid").arg("gitdep").exec_with_output().unwrap();
1651+
let output = p.cargo("pkgid").arg("gitdep").run();
16521652
let gitdep_pkgid = String::from_utf8(output.stdout).unwrap();
16531653
let gitdep_pkgid = gitdep_pkgid.trim();
16541654
assert_e2e().eq(

tests/testsuite/freshness.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2527,8 +2527,7 @@ LLVM version: 9.0
25272527
let output = p
25282528
.cargo("check --message-format=json")
25292529
.env("RUSTC", compiler.bin(version))
2530-
.exec_with_output()
2531-
.unwrap();
2530+
.run();
25322531
// Collect the filenames generated.
25332532
let mut artifacts: Vec<_> = std::str::from_utf8(&output.stdout)
25342533
.unwrap()

tests/testsuite/freshness_checksum.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2435,8 +2435,7 @@ LLVM version: 9.0
24352435
.cargo("check -Zchecksum-freshness --message-format=json")
24362436
.masquerade_as_nightly_cargo(&["checksum-freshness"])
24372437
.env("RUSTC", compiler.bin(version))
2438-
.exec_with_output()
2439-
.unwrap();
2438+
.run();
24402439
// Collect the filenames generated.
24412440
let mut artifacts: Vec<_> = std::str::from_utf8(&output.stdout)
24422441
.unwrap()

tests/testsuite/future_incompat_report.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,7 @@ The package `second-dep v0.0.2` currently triggers the following future incompat
252252
let output = p
253253
.cargo("check")
254254
.env("RUSTFLAGS", "-Zfuture-incompat-test")
255-
.exec_with_output()
256-
.unwrap();
255+
.run();
257256

258257
// Extract the 'id' from the stdout. We are looking
259258
// for the id in a line of the form "run `cargo report future-incompatibilities --id yZ7S`"
@@ -282,10 +281,7 @@ The package `second-dep v0.0.2` currently triggers the following future incompat
282281
.run();
283282

284283
// Test without --id, and also the full output of the report.
285-
let output = p
286-
.cargo("report future-incompat")
287-
.exec_with_output()
288-
.unwrap();
284+
let output = p.cargo("report future-incompat").run();
289285
let output = std::str::from_utf8(&output.stdout).unwrap();
290286
assert!(output.starts_with("The following warnings were discovered"));
291287
let mut lines = output

tests/testsuite/git.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3396,7 +3396,7 @@ fn historical_lockfile_works_with_vendor() {
33963396
.file("src/lib.rs", "")
33973397
.build();
33983398

3399-
let output = project.cargo("vendor").exec_with_output().unwrap();
3399+
let output = project.cargo("vendor").run();
34003400
project.change_file(
34013401
".cargo/config.toml",
34023402
str::from_utf8(&output.stdout).unwrap(),

tests/testsuite/help.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::str::from_utf8;
77
use cargo_test_support::prelude::*;
88
use cargo_test_support::registry::Package;
99
use cargo_test_support::str;
10-
use cargo_test_support::{basic_manifest, cargo_exe, cargo_process, paths, process, project};
10+
use cargo_test_support::{basic_manifest, cargo_process, paths, project};
1111

1212
#[cargo_test]
1313
fn help() {
@@ -83,13 +83,9 @@ fn help_with_man_and_path(
8383
.unwrap()
8484
};
8585

86-
let output = process(&cargo_exe())
87-
.arg("help")
88-
.arg(subcommand)
86+
let output = cargo_process(&format!("help {subcommand}"))
8987
.env("PATH", path)
90-
.exec_with_output()
91-
.unwrap();
92-
assert!(output.status.success());
88+
.run();
9389
let stderr = from_utf8(&output.stderr).unwrap();
9490
if display_command.is_empty() {
9591
assert_eq!(stderr, "");
@@ -101,13 +97,9 @@ fn help_with_man_and_path(
10197
}
10298

10399
fn help_with_stdout_and_path(subcommand: &str, path: &Path) -> String {
104-
let output = process(&cargo_exe())
105-
.arg("help")
106-
.arg(subcommand)
100+
let output = cargo_process(&format!("help {subcommand}"))
107101
.env("PATH", path)
108-
.exec_with_output()
109-
.unwrap();
110-
assert!(output.status.success());
102+
.run();
111103
let stderr = from_utf8(&output.stderr).unwrap();
112104
assert_eq!(stderr, "");
113105
let stdout = from_utf8(&output.stdout).unwrap();

tests/testsuite/lto.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
use std::process::Output;
2-
31
use cargo::core::compiler::Lto;
42
use cargo_test_support::prelude::*;
53
use cargo_test_support::registry::Package;
4+
use cargo_test_support::RawOutput;
65
use cargo_test_support::{basic_manifest, project, str, Project};
76

87
#[cargo_test]
@@ -509,7 +508,7 @@ fn project_with_dep(crate_types: &str) -> Project {
509508
///
510509
/// `krate_info` is extra compiler flags used to distinguish this if the same
511510
/// crate name is being built multiple times.
512-
fn verify_lto(output: &Output, krate: &str, krate_info: &str, expected_lto: Lto) {
511+
fn verify_lto(output: &RawOutput, krate: &str, krate_info: &str, expected_lto: Lto) {
513512
let stderr = std::str::from_utf8(&output.stderr).unwrap();
514513
let mut matches = stderr.lines().filter(|line| {
515514
line.contains("Running")
@@ -554,7 +553,7 @@ fn verify_lto(output: &Output, krate: &str, krate_info: &str, expected_lto: Lto)
554553
#[cargo_test]
555554
fn cdylib_and_rlib() {
556555
let p = project_with_dep("'cdylib', 'rlib'");
557-
let output = p.cargo("build --release -v").exec_with_output().unwrap();
556+
let output = p.cargo("build --release -v").run();
558557
// `registry` is ObjectAndBitcode because it needs Object for the
559558
// rlib, and Bitcode for the cdylib (which doesn't support LTO).
560559
verify_lto(
@@ -627,7 +626,7 @@ fn cdylib_and_rlib() {
627626
#[cargo_test]
628627
fn dylib() {
629628
let p = project_with_dep("'dylib'");
630-
let output = p.cargo("build --release -v").exec_with_output().unwrap();
629+
let output = p.cargo("build --release -v").run();
631630
// `registry` is OnlyObject because rustc doesn't support LTO with dylibs.
632631
verify_lto(&output, "registry", "--crate-type lib", Lto::OnlyObject);
633632
// `registry_shared` is both because it is needed by both bar (Object) and
@@ -860,7 +859,7 @@ fn dylib_rlib_bin() {
860859
.file("src/bin/ferret.rs", "fn main() { foo::foo(); }")
861860
.build();
862861

863-
let output = p.cargo("build --release -v").exec_with_output().unwrap();
862+
let output = p.cargo("build --release -v").run();
864863
verify_lto(
865864
&output,
866865
"foo",

tests/testsuite/package.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3143,7 +3143,7 @@ path = "src/lib.rs"
31433143
}
31443144

31453145
fn verify_packaged_status_line(
3146-
output: std::process::Output,
3146+
output: cargo_test_support::RawOutput,
31473147
num_files: usize,
31483148
uncompressed_size: u64,
31493149
compressed_size: u64,
@@ -3228,7 +3228,7 @@ version = "0.0.1"
32283228
+ main_rs_contents.len()
32293229
+ cargo_toml_contents.len()
32303230
+ cargo_lock_contents.len()) as u64;
3231-
let output = p.cargo("package").exec_with_output().unwrap();
3231+
let output = p.cargo("package").run();
32323232

32333233
assert!(p.root().join("target/package/foo-0.0.1.crate").is_file());
32343234
p.cargo("package -l")
@@ -3333,7 +3333,7 @@ version = "0.0.1"
33333333
+ cargo_lock_contents.len()
33343334
+ bar_txt_contents.len()) as u64;
33353335

3336-
let output = p.cargo("package").exec_with_output().unwrap();
3336+
let output = p.cargo("package").run();
33373337
assert!(p.root().join("target/package/foo-0.0.1.crate").is_file());
33383338
p.cargo("package -l")
33393339
.with_stdout_data(str![[r#"
@@ -3452,7 +3452,7 @@ version = "0.0.1"
34523452
+ cargo_lock_contents.len()
34533453
+ bar_txt_contents.len() * 2) as u64;
34543454

3455-
let output = p.cargo("package").exec_with_output().unwrap();
3455+
let output = p.cargo("package").run();
34563456
assert!(p.root().join("target/package/foo-0.0.1.crate").is_file());
34573457
p.cargo("package -l")
34583458
.with_stdout_data(str![[r#"

tests/testsuite/pkgid.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ fn pkgid_json_message_metadata_consistency() {
301301

302302
p.cargo("generate-lockfile").run();
303303

304-
let output = p.cargo("pkgid").arg("foo").exec_with_output().unwrap();
304+
let output = p.cargo("pkgid").arg("foo").run();
305305
let pkgid = String::from_utf8(output.stdout).unwrap();
306306
let pkgid = pkgid.trim();
307307
assert_e2e().eq(pkgid, str!["path+[ROOTURL]/foo#0.5.0"]);

tests/testsuite/registry_auth.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,7 @@ fn token_not_logged() {
542542
.replace_crates_io(crates_io.index_url())
543543
.env("CARGO_HTTP_DEBUG", "true")
544544
.env("CARGO_LOG", "trace")
545-
.exec_with_output()
546-
.unwrap();
545+
.run();
547546
let log = String::from_utf8(output.stderr).unwrap();
548547
assert_e2e().eq(
549548
&log,

0 commit comments

Comments
 (0)