Skip to content

Commit bf517eb

Browse files
committed
Deduplicate abort checking after running a command
1 parent c0ff3b3 commit bf517eb

File tree

6 files changed

+23
-29
lines changed

6 files changed

+23
-29
lines changed

src/aux_builds.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
use crate::{
55
build_manager::{Build, BuildManager},
6-
core::run_command,
76
custom_flags::Flag,
87
default_per_file_config, display,
98
per_test_config::{Comments, TestConfig},
@@ -123,7 +122,7 @@ impl Build for AuxBuilder {
123122

124123
aux_cmd.arg("--emit=link");
125124
let filename = self.aux_file.file_stem().unwrap().to_str().unwrap();
126-
let output = run_command(&mut aux_cmd)?;
125+
let output = config.config.run_command(&mut aux_cmd)?;
127126
if !output.status.success() {
128127
let error = Error::Command {
129128
kind: "compilation of aux build failed".to_string(),
@@ -139,9 +138,7 @@ impl Build for AuxBuilder {
139138

140139
// Now run the command again to fetch the output filenames
141140
aux_cmd.arg("--print").arg("file-names");
142-
let output = run_command(&mut aux_cmd)?;
143-
144-
config.aborted()?;
141+
let output = config.config.run_command(&mut aux_cmd)?;
145142

146143
assert!(output.status.success());
147144

src/build_manager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub trait Build {
2828
pub struct BuildManager {
2929
#[allow(clippy::type_complexity)]
3030
cache: RwLock<HashMap<String, Arc<OnceLock<Result<Vec<OsString>, ()>>>>>,
31-
config: Config,
31+
pub(crate) config: Config,
3232
new_job_submitter: Sender<NewJob>,
3333
}
3434

src/config.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use std::{
1717
collections::BTreeMap,
1818
num::NonZeroUsize,
1919
path::{Path, PathBuf},
20+
process::{Command, Output},
2021
sync::{atomic::AtomicBool, Arc},
2122
};
2223

@@ -461,6 +462,21 @@ impl Config {
461462
Ok(())
462463
}
463464
}
465+
466+
pub(crate) fn run_command(&self, cmd: &mut Command) -> Result<Output, Errored> {
467+
self.aborted()?;
468+
469+
let output = cmd.output().map_err(|err| Errored {
470+
errors: vec![],
471+
stderr: err.to_string().into_bytes(),
472+
stdout: format!("could not spawn `{:?}` as a process", cmd.get_program()).into_bytes(),
473+
command: format!("{cmd:?}"),
474+
})?;
475+
476+
self.aborted()?;
477+
478+
Ok(output)
479+
}
464480
}
465481

466482
/// Fail the test when mismatches are found, if provided the command string

src/core.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! Basic operations useful for building a testsuite
22
3-
use crate::test_result::Errored;
43
use color_eyre::eyre::Result;
54
use crossbeam_channel::unbounded;
65
use crossbeam_channel::Receiver;
@@ -10,23 +9,9 @@ use std::num::NonZeroUsize;
109
use std::path::Component;
1110
use std::path::Path;
1211
use std::path::Prefix;
13-
use std::process::Command;
14-
use std::process::Output;
1512
use std::sync::OnceLock;
1613
use std::thread;
1714

18-
pub(crate) fn run_command(cmd: &mut Command) -> Result<Output, Errored> {
19-
match cmd.output() {
20-
Err(err) => Err(Errored {
21-
errors: vec![],
22-
stderr: err.to_string().into_bytes(),
23-
stdout: format!("could not spawn `{:?}` as a process", cmd.get_program()).into_bytes(),
24-
command: format!("{cmd:?}"),
25-
}),
26-
Ok(output) => Ok(output),
27-
}
28-
}
29-
3015
/// Remove the common prefix of this path and the `root_dir`.
3116
pub(crate) fn strip_path_prefix<'a>(
3217
path: &'a Path,

src/dependencies.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
33
use crate::{
44
build_manager::{Build, BuildManager},
5-
core::run_command,
65
custom_flags::Flag,
76
per_test_config::TestConfig,
87
test_result::Errored,
@@ -38,7 +37,7 @@ fn cfgs(config: &Config) -> Result<Vec<Cfg>, Errored> {
3837
let mut cmd = config.program.build(&config.out_dir);
3938
cmd.arg(cfg);
4039
cmd.arg("--target").arg(config.target.as_ref().unwrap());
41-
let output = run_command(&mut cmd)?;
40+
let output = config.run_command(&mut cmd)?;
4241

4342
if !output.status.success() {
4443
return Err(Errored {
@@ -97,7 +96,7 @@ fn build_dependencies_inner(
9796

9897
build.arg("--message-format=json");
9998

100-
let output = run_command(&mut build)?;
99+
let output = config.run_command(&mut build)?;
101100

102101
if !output.status.success() {
103102
let stdout = output
@@ -193,7 +192,7 @@ fn build_dependencies_inner(
193192
.arg(&info.crate_manifest_path);
194193
info.program.apply_env(&mut metadata);
195194
set_locking(&mut metadata);
196-
let output = run_command(&mut metadata)?;
195+
let output = config.run_command(&mut metadata)?;
197196

198197
if !output.status.success() {
199198
return Err(Errored {

src/per_test_config.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,7 @@ impl TestConfig {
380380
cmd.stdin(std::fs::File::open(stdin).unwrap());
381381
}
382382

383-
let output = crate::core::run_command(&mut cmd)?;
384-
385-
// Do not bless aborted tests
386-
self.aborted()?;
383+
let output = build_manager.config.run_command(&mut cmd)?;
387384

388385
let output = self.check_test_result(&cmd, output)?;
389386

0 commit comments

Comments
 (0)