diff --git a/tests/by-util/test_rm.rs b/tests/by-util/test_rm.rs index b36c11d47..1ffd2cdf0 100644 --- a/tests/by-util/test_rm.rs +++ b/tests/by-util/test_rm.rs @@ -1,3 +1,5 @@ +use std::process::Stdio; + use crate::common::util::*; #[test] @@ -373,7 +375,12 @@ fn test_rm_descend_directory() { at.touch(file_1); at.touch(file_2); - let mut child = scene.ucmd().arg("-ri").arg("a").run_no_wait(); + let mut child = scene + .ucmd() + .set_stdin(Stdio::piped()) + .arg("-ri") + .arg("a") + .run_no_wait(); child.try_write_in(yes.as_bytes()).unwrap(); child.try_write_in(yes.as_bytes()).unwrap(); child.try_write_in(yes.as_bytes()).unwrap(); @@ -445,7 +452,12 @@ fn test_rm_prompts() { .arg(file_2) .succeeds(); - let mut child = scene.ucmd().arg("-ri").arg("a").run_no_wait(); + let mut child = scene + .ucmd() + .set_stdin(Stdio::piped()) + .arg("-ri") + .arg("a") + .run_no_wait(); for _ in 0..9 { child.try_write_in(yes.as_bytes()).unwrap(); } @@ -486,7 +498,12 @@ fn test_rm_force_prompts_order() { at.touch(empty_file); // This should cause rm to prompt to remove regular empty file - let mut child = scene.ucmd().arg("-fi").arg(empty_file).run_no_wait(); + let mut child = scene + .ucmd() + .set_stdin(Stdio::piped()) + .arg("-fi") + .arg(empty_file) + .run_no_wait(); child.try_write_in(yes.as_bytes()).unwrap(); let result = child.wait().unwrap(); diff --git a/tests/by-util/test_tail.rs b/tests/by-util/test_tail.rs index 6ea075541..c2a81b3db 100644 --- a/tests/by-util/test_tail.rs +++ b/tests/by-util/test_tail.rs @@ -351,7 +351,11 @@ fn test_follow_stdin_descriptor() { let mut args = vec!["-f", "-"]; for _ in 0..2 { - let mut p = ts.ucmd().args(&args).run_no_wait(); + let mut p = ts + .ucmd() + .set_stdin(Stdio::piped()) + .args(&args) + .run_no_wait(); p.make_assertion_with_delay(500).is_alive(); p.kill() .make_assertion() diff --git a/tests/by-util/test_tee.rs b/tests/by-util/test_tee.rs index 5a2f26724..e90c4dd48 100644 --- a/tests/by-util/test_tee.rs +++ b/tests/by-util/test_tee.rs @@ -111,7 +111,7 @@ mod linux_only { use crate::common::util::*; use std::fs::File; - use std::process::Output; + use std::process::{Output, Stdio}; fn make_broken_pipe() -> File { use libc::c_int; @@ -135,6 +135,7 @@ mod linux_only { #[allow(deprecated)] let output = proc .ignore_stdin_write_error() + .set_stdin(Stdio::piped()) .run_no_wait() .pipe_in_and_wait_with_output(content.as_bytes()); diff --git a/tests/common/util.rs b/tests/common/util.rs index 9b87c3d22..c60a3637e 100644 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -1105,6 +1105,7 @@ impl UCommand { "{}", MULTIPLE_STDIN_MEANINGLESS ); + self.set_stdin(Stdio::piped()); self.bytes_into_stdin = Some(input.into()); self } @@ -1170,8 +1171,7 @@ impl UCommand { let command = self .raw - // TODO: use Stdio::null() as default to avoid accidental deadlocks ? - .stdin(self.stdin.take().unwrap_or_else(Stdio::piped)) + .stdin(self.stdin.take().unwrap_or_else(Stdio::null)) .stdout(Stdio::from(output.try_clone().unwrap())) .stderr(Stdio::from(output.try_clone().unwrap())); captured_stdout = Some(output); @@ -1197,8 +1197,7 @@ impl UCommand { }; self.raw - // TODO: use Stdio::null() as default to avoid accidental deadlocks ? - .stdin(self.stdin.take().unwrap_or_else(Stdio::piped)) + .stdin(self.stdin.take().unwrap_or_else(Stdio::null)) .stdout(stdout) .stderr(stderr) }; @@ -2696,7 +2695,7 @@ mod tests { #[test] fn test_uchild_when_pipe_in() { let ts = TestScenario::new("cat"); - let mut child = ts.ucmd().run_no_wait(); + let mut child = ts.ucmd().set_stdin(Stdio::piped()).run_no_wait(); child.pipe_in("content"); child.wait().unwrap().stdout_only("content").success(); @@ -2721,6 +2720,7 @@ mod tests { let mut child = ts .ucmd() + .set_stdin(Stdio::piped()) .stderr_to_stdout() .args(&["-riv", "a"]) .run_no_wait();