Skip to content

Commit 8e65f73

Browse files
committed
difftest: unify cargo cmd setup
1 parent 4ca44fe commit 8e65f73

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

tests/difftests/bin/src/main.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
use anyhow::Result;
2-
use std::{
3-
env,
4-
process::{self, Command},
5-
};
2+
use std::{env, process};
63
use tester::{
74
ColorConfig, DynTestName, OutputFormat, RunIgnored, ShouldPanic, TestDesc, TestDescAndFn,
85
TestFn, TestType, run_tests_console,
@@ -11,6 +8,7 @@ use tester::{
118
use tracing_subscriber::FmtSubscriber;
129

1310
mod runner;
11+
use crate::runner::setup_cargo_cmd;
1412
use runner::Runner;
1513

1614
fn main() -> Result<()> {
@@ -71,11 +69,8 @@ fn main() -> Result<()> {
7169

7270
// We build first to ensure that the tests are compiled before running them and to
7371
// passthrough stdout and stderr from cargo to help debugging.
74-
let mut cmd = Command::new("cargo");
75-
let cmd = cmd.arg("build").arg("--release");
76-
runner::forward_features(cmd);
77-
cmd.current_dir(&base)
78-
.stderr(process::Stdio::inherit())
72+
let mut cmd = setup_cargo_cmd("build", &base.join("Cargo.toml"))?;
73+
cmd.stderr(process::Stdio::inherit())
7974
.stdout(process::Stdio::inherit());
8075
tracing::debug!("Running cargo command: {:?}", cmd);
8176

tests/difftests/bin/src/runner.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,7 @@ impl Runner {
134134
write!(config_file, "{}", config_json).map_err(|e| RunnerError::Io { source: e })?;
135135
trace!("Config file created at {}", config_file.path().display());
136136

137-
let mut cmd = Command::new("cargo");
138-
cmd.arg("run").arg("--release").arg("--manifest-path").arg(
139-
manifest_path
140-
.to_str()
141-
.ok_or_else(|| RunnerError::Manifest {
142-
path: manifest_path.clone(),
143-
})?,
144-
);
145-
forward_features(&mut cmd);
137+
let mut cmd = setup_cargo_cmd("run", &manifest_path)?;
146138
cmd.arg("--").arg(
147139
config_file
148140
.path()
@@ -328,6 +320,22 @@ impl Runner {
328320
}
329321
}
330322

323+
pub fn setup_cargo_cmd(subcommand: &str, manifest_path: &Path) -> Result<Command, RunnerError> {
324+
let mut cmd = Command::new("cargo");
325+
cmd.arg(subcommand)
326+
.arg("--release")
327+
.arg("--manifest-path")
328+
.arg(
329+
manifest_path
330+
.to_str()
331+
.ok_or_else(|| RunnerError::Manifest {
332+
path: PathBuf::from(manifest_path),
333+
})?,
334+
);
335+
forward_features(&mut cmd);
336+
Ok(cmd)
337+
}
338+
331339
pub fn forward_features(cmd: &mut Command) {
332340
cmd.arg("--features");
333341
#[cfg(feature = "use-compiled-tools")]

0 commit comments

Comments
 (0)