Don't always capture stdout, selectively do it

Add a separate function for running a child and capturing stdout
master
Alex Crichton 6 years ago
parent 116c456a19
commit 7c8d1a80a8
  1. 2
      src/bindgen.rs
  2. 3
      src/build.rs
  3. 19
      src/child.rs
  4. 6
      tests/all/test.rs

@ -231,7 +231,7 @@ pub fn wasm_bindgen_build(
fn wasm_bindgen_version_check(bindgen_path: &PathBuf, dep_version: &str) -> bool {
let mut cmd = Command::new(bindgen_path);
cmd.arg("--version");
child::run(cmd, "wasm-bindgen")
child::run_capture_stdout(cmd, "wasm-bindgen")
.map(|stdout| {
stdout
.trim()

@ -52,7 +52,8 @@ fn rustc_minor_version() -> Option<u32> {
pub fn rustup_add_wasm_target(step: &Step) -> Result<(), Error> {
let mut cmd = Command::new("rustc");
cmd.arg("--print").arg("sysroot");
let output = child::run(cmd, "rustc").context("Learning about rustc's sysroot")?;
let output =
child::run_capture_stdout(cmd, "rustc").context("Learning about rustc's sysroot")?;
let sysroot = Path::new(output.trim());
// If this exists then we for sure have a wasm32 target so there's no need

@ -24,7 +24,24 @@ pub fn new_command(program: &str) -> Command {
}
/// Run the given command and return its stdout.
pub fn run(mut command: Command, command_name: &str) -> Result<String, Error> {
pub fn run(mut command: Command, command_name: &str) -> Result<(), Error> {
info!("Running {:?}", command);
let status = command.status()?;
if status.success() {
Ok(())
} else {
bail!(
"failed to execute `{}`: exited with {}",
command_name,
status
)
}
}
/// Run the given command and return its stdout.
pub fn run_capture_stdout(mut command: Command, command_name: &str) -> Result<String, Error> {
info!("Running {:?}", command);
let output = command

@ -331,9 +331,9 @@ fn test_output_is_printed_once_in_both_stdout_and_failures() {
.arg("--node")
.assert()
.failure()
.stderr(predicate::function(|err: &str| {
// but the err string will capture both stdout and failures,
.stdout(predicate::function(|out: &str| {
// but the out string will capture both stdout and failures,
// so we will get a log that count twice
err.matches("YABBA DABBA DOO").count() == log_cnt * 2
out.matches("YABBA DABBA DOO").count() == log_cnt * 2
}));
}

Loading…
Cancel
Save