Skip to content

Commit 3104365

Browse files
committed
compiletest: Unify cmd2procres with run_command_to_procres
1 parent 23ea77b commit 3104365

File tree

1 file changed

+19
-29
lines changed

1 file changed

+19
-29
lines changed

src/tools/compiletest/src/runtest.rs

+19-29
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,20 @@ impl<'test> TestCx<'test> {
506506
}
507507
}
508508

509+
/// Runs a [`Command`] and waits for it to finish, then converts its exit
510+
/// status and output streams into a [`ProcRes`].
511+
///
512+
/// The command might have succeeded or failed; it is the caller's
513+
/// responsibility to check the exit status and take appropriate action.
514+
///
515+
/// # Panics
516+
/// Panics if the command couldn't be executed at all
517+
/// (e.g. because the executable could not be found).
518+
#[must_use = "caller should check whether the command succeeded"]
509519
fn run_command_to_procres(&self, cmd: &mut Command) -> ProcRes {
510-
let output = cmd.output().unwrap_or_else(|e| panic!("failed to exec `{cmd:?}`: {e:?}"));
520+
let output = cmd
521+
.output()
522+
.unwrap_or_else(|e| self.fatal(&format!("failed to exec `{cmd:?}` because: {e}")));
511523

512524
let proc_res = ProcRes {
513525
status: output.status,
@@ -1232,7 +1244,7 @@ impl<'test> TestCx<'test> {
12321244
} else {
12331245
self.config.lldb_python_dir.as_ref().unwrap().to_string()
12341246
};
1235-
self.cmd2procres(
1247+
self.run_command_to_procres(
12361248
Command::new(&self.config.python)
12371249
.arg(&lldb_script_path)
12381250
.arg(test_executable)
@@ -1242,28 +1254,6 @@ impl<'test> TestCx<'test> {
12421254
)
12431255
}
12441256

1245-
fn cmd2procres(&self, cmd: &mut Command) -> ProcRes {
1246-
let (status, out, err) = match cmd.output() {
1247-
Ok(Output { status, stdout, stderr }) => {
1248-
(status, String::from_utf8(stdout).unwrap(), String::from_utf8(stderr).unwrap())
1249-
}
1250-
Err(e) => self.fatal(&format!(
1251-
"Failed to setup Python process for \
1252-
LLDB script: {}",
1253-
e
1254-
)),
1255-
};
1256-
1257-
self.dump_output(&out, &err);
1258-
ProcRes {
1259-
status,
1260-
stdout: out,
1261-
stderr: err,
1262-
truncated: Truncated::No,
1263-
cmdline: format!("{:?}", cmd),
1264-
}
1265-
}
1266-
12671257
fn cleanup_debug_info_options(&self, options: &Vec<String>) -> Vec<String> {
12681258
// Remove options that are either unwanted (-O) or may lead to duplicates due to RUSTFLAGS.
12691259
let options_to_remove = ["-O".to_owned(), "-g".to_owned(), "--debuginfo".to_owned()];
@@ -2683,7 +2673,7 @@ impl<'test> TestCx<'test> {
26832673
if self.config.bless {
26842674
cmd.arg("--bless");
26852675
}
2686-
let res = self.cmd2procres(&mut cmd);
2676+
let res = self.run_command_to_procres(&mut cmd);
26872677
if !res.status.success() {
26882678
self.fatal_proc_rec_with_ctx("htmldocck failed!", &res, |mut this| {
26892679
this.compare_to_default_rustdoc(&out_dir)
@@ -2860,7 +2850,7 @@ impl<'test> TestCx<'test> {
28602850
let root = self.config.find_rust_src_root().unwrap();
28612851
let mut json_out = out_dir.join(self.testpaths.file.file_stem().unwrap());
28622852
json_out.set_extension("json");
2863-
let res = self.cmd2procres(
2853+
let res = self.run_command_to_procres(
28642854
Command::new(self.config.jsondocck_path.as_ref().unwrap())
28652855
.arg("--doc-dir")
28662856
.arg(root.join(&out_dir))
@@ -2878,7 +2868,7 @@ impl<'test> TestCx<'test> {
28782868
let mut json_out = out_dir.join(self.testpaths.file.file_stem().unwrap());
28792869
json_out.set_extension("json");
28802870

2881-
let res = self.cmd2procres(
2871+
let res = self.run_command_to_procres(
28822872
Command::new(self.config.jsondoclint_path.as_ref().unwrap()).arg(&json_out),
28832873
);
28842874

@@ -3526,7 +3516,7 @@ impl<'test> TestCx<'test> {
35263516
cmd.arg("--sysroot").arg(&stage0_sysroot);
35273517
}
35283518

3529-
let res = self.cmd2procres(&mut cmd);
3519+
let res = self.run_command_to_procres(&mut cmd);
35303520
if !res.status.success() {
35313521
self.fatal_proc_rec("run-make test failed: could not build `rmake.rs` recipe", &res);
35323522
}
@@ -3687,7 +3677,7 @@ impl<'test> TestCx<'test> {
36873677
let root = self.config.find_rust_src_root().unwrap();
36883678
let file_stem =
36893679
self.testpaths.file.file_stem().and_then(|f| f.to_str()).expect("no file stem");
3690-
let res = self.cmd2procres(
3680+
let res = self.run_command_to_procres(
36913681
Command::new(&nodejs)
36923682
.arg(root.join("src/tools/rustdoc-js/tester.js"))
36933683
.arg("--doc-folder")

0 commit comments

Comments
 (0)