Skip to content

Commit c40e47c

Browse files
committed
Use process::Output instead of passing its fields individually
1 parent 457e4a9 commit c40e47c

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

src/lib.rs

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use std::collections::{HashSet, VecDeque};
2121
use std::ffi::OsString;
2222
use std::num::NonZeroUsize;
2323
use std::path::{Component, Path, PathBuf, Prefix};
24-
use std::process::{Command, ExitStatus, Output};
24+
use std::process::{Command, Output};
2525
use std::thread;
2626
use test_result::{Errored, TestOk, TestResult, TestRun};
2727

@@ -602,7 +602,7 @@ impl dyn TestStatus {
602602
cmd.stdin(std::fs::File::open(stdin).unwrap());
603603
}
604604

605-
let (cmd, status, stderr, stdout) = run_command(cmd)?;
605+
let (cmd, output) = run_command(cmd)?;
606606

607607
let mode = comments.mode(revision)?;
608608
let cmd = check_test_result(
@@ -615,35 +615,29 @@ impl dyn TestStatus {
615615
&config,
616616
revision,
617617
comments,
618-
status,
619-
&stdout,
620-
&stderr,
618+
&output,
621619
)?;
622620

623621
if let Mode::Run { .. } = *mode {
624622
return run_test_binary(mode, path, revision, comments, cmd, &config);
625623
}
626624

627625
run_rustfix(
628-
&stderr, &stdout, path, comments, revision, &config, *mode, extra_args,
626+
&output, path, comments, revision, &config, *mode, extra_args,
629627
)?;
630628
Ok(TestOk::Ok)
631629
}
632630
}
633631

634-
fn run_command(mut cmd: Command) -> Result<(Command, ExitStatus, Vec<u8>, Vec<u8>), Errored> {
632+
fn run_command(mut cmd: Command) -> Result<(Command, Output), Errored> {
635633
match cmd.output() {
636634
Err(err) => Err(Errored {
637635
errors: vec![],
638636
stderr: err.to_string().into_bytes(),
639637
stdout: format!("could not spawn `{:?}` as a process", cmd.get_program()).into_bytes(),
640638
command: cmd,
641639
}),
642-
Ok(Output {
643-
status,
644-
stdout,
645-
stderr,
646-
}) => Ok((cmd, status, stderr, stdout)),
640+
Ok(output) => Ok((cmd, output)),
647641
}
648642
}
649643

@@ -764,8 +758,7 @@ fn run_test_binary(
764758
}
765759

766760
fn run_rustfix(
767-
stderr: &[u8],
768-
stdout: &[u8],
761+
output: &Output,
769762
path: &Path,
770763
comments: &Comments,
771764
revision: &str,
@@ -786,7 +779,7 @@ fn run_rustfix(
786779
let fixed_code = (no_run_rustfix.is_none() && global_rustfix.enabled())
787780
.then_some(())
788781
.and_then(|()| {
789-
let suggestions = std::str::from_utf8(stderr)
782+
let suggestions = std::str::from_utf8(&output.stderr)
790783
.unwrap()
791784
.lines()
792785
.flat_map(|line| {
@@ -828,8 +821,8 @@ fn run_rustfix(
828821
.map_err(|err| Errored {
829822
command: Command::new(format!("rustfix {}", path.display())),
830823
errors: vec![Error::Rustfix(err)],
831-
stderr: stderr.into(),
832-
stdout: stdout.into(),
824+
stderr: output.stderr.clone(),
825+
stdout: output.stdout.clone(),
833826
})?;
834827

835828
let edition = comments.edition(revision)?.into();
@@ -936,12 +929,14 @@ fn check_test_result(
936929
config: &Config,
937930
revision: &str,
938931
comments: &Comments,
939-
status: ExitStatus,
940-
stdout: &[u8],
941-
stderr: &[u8],
932+
Output {
933+
status,
934+
stdout,
935+
stderr,
936+
}: &Output,
942937
) -> Result<Command, Errored> {
943938
let mut errors = vec![];
944-
errors.extend(mode.ok(status).err());
939+
errors.extend(mode.ok(*status).err());
945940
// Always remove annotation comments from stderr.
946941
let diagnostics = rustc_stderr::process(path, stderr);
947942
check_test_output(
@@ -969,7 +964,7 @@ fn check_test_result(
969964
command,
970965
errors,
971966
stderr: diagnostics.rendered,
972-
stdout: stdout.into(),
967+
stdout: stdout.clone(),
973968
})
974969
}
975970
}

0 commit comments

Comments
 (0)