Skip to content

Commit

Permalink
Eliminate two uses of subprocess
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed May 10, 2024
1 parent 7ce801a commit be5f9a2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
25 changes: 12 additions & 13 deletions cargo-test-fuzz/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ use std::{
fmt::{Debug, Formatter},
fs::{create_dir_all, read, read_dir, remove_dir_all, File},
io::{BufRead, Read},
iter,
path::{Path, PathBuf},
process::{exit, Command},
process::{exit, Command, Stdio},
sync::OnceLock,
time::Duration,
};
Expand Down Expand Up @@ -263,19 +262,19 @@ fn build(opts: &TestFuzz, quiet: bool) -> Result<Vec<Executable>> {
// `AFL_QUIET=1` doesn't work here, so pipe standard error to /dev/null.
// smoelius: Suppressing all of standard error is too extreme. For now, suppress only when
// displaying/replaying.
let mut exec = Exec::cmd("cargo")
.args(
&args
.iter()
.chain(iter::once(&"--message-format=json"))
.collect::<Vec<_>>(),
)
.stdout(Redirection::Pipe);
let mut command = Command::new("cargo");
command
.args(&args)
.arg("--message-format=json")
.stdout(Stdio::piped());
if quiet && !opts.verbose {
exec = exec.stderr(NullFile);
command.stderr(Stdio::null());
}
debug!("{:?}", exec);
let mut popen = exec.clone().popen()?;
debug!("{command:?}");
let exec = format!("{command:?}");
let mut popen = command
.spawn()
.with_context(|| format!("Could not spawn `{exec:?}`"))?;
let artifacts = popen
.stdout
.take()
Expand Down
1 change: 0 additions & 1 deletion testing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ if_chain = "1.0"
log = "0.4"
once_cell = "1.19"
retry = "2.0"
subprocess = "0.2"

internal = { path = "../internal", package = "test-fuzz-internal", version = "=5.1.0" }

Expand Down
16 changes: 11 additions & 5 deletions testing/src/examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ use if_chain::if_chain;
use internal::serde_format;
use log::debug;
use once_cell::sync::Lazy;
use std::path::Path;
use subprocess::{Exec, Redirection};
use std::{
path::Path,
process::{Command as StdCommand, Stdio},
};

pub static MANIFEST_PATH: Lazy<String> = Lazy::new(|| {
#[cfg_attr(dylint_lib = "general", allow(abs_home_path))]
Expand Down Expand Up @@ -35,9 +37,13 @@ pub fn test(krate: &str, test: &str) -> Result<Command> {
];
args.extend_from_slice(&["--no-run", "--message-format=json"]);

let exec = Exec::cmd("cargo").args(&args).stdout(Redirection::Pipe);
debug!("{:?}", exec);
let mut popen = exec.clone().popen()?;
let mut command = StdCommand::new("cargo");
command.args(&args).stdout(Stdio::piped());
debug!("{command:?}");
let exec = format!("{command:?}");
let mut popen = command
.spawn()
.with_context(|| format!("Could not spawn `{exec:?}`"))?;
let messages = popen
.stdout
.take()
Expand Down

0 comments on commit be5f9a2

Please sign in to comment.