mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
tests/util: Use Stdio::null as default in UCommand for Child stdin instead of Stdio::piped
This commit is contained in:
parent
c2e4da97da
commit
9b35c5d5c1
4 changed files with 32 additions and 10 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
use std::process::Stdio;
|
||||||
|
|
||||||
use crate::common::util::*;
|
use crate::common::util::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -373,7 +375,12 @@ fn test_rm_descend_directory() {
|
||||||
at.touch(file_1);
|
at.touch(file_1);
|
||||||
at.touch(file_2);
|
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();
|
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)
|
.arg(file_2)
|
||||||
.succeeds();
|
.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 {
|
for _ in 0..9 {
|
||||||
child.try_write_in(yes.as_bytes()).unwrap();
|
child.try_write_in(yes.as_bytes()).unwrap();
|
||||||
}
|
}
|
||||||
|
@ -486,7 +498,12 @@ fn test_rm_force_prompts_order() {
|
||||||
at.touch(empty_file);
|
at.touch(empty_file);
|
||||||
|
|
||||||
// This should cause rm to prompt to remove regular 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();
|
child.try_write_in(yes.as_bytes()).unwrap();
|
||||||
|
|
||||||
let result = child.wait().unwrap();
|
let result = child.wait().unwrap();
|
||||||
|
|
|
@ -351,7 +351,11 @@ fn test_follow_stdin_descriptor() {
|
||||||
|
|
||||||
let mut args = vec!["-f", "-"];
|
let mut args = vec!["-f", "-"];
|
||||||
for _ in 0..2 {
|
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.make_assertion_with_delay(500).is_alive();
|
||||||
p.kill()
|
p.kill()
|
||||||
.make_assertion()
|
.make_assertion()
|
||||||
|
|
|
@ -111,7 +111,7 @@ mod linux_only {
|
||||||
use crate::common::util::*;
|
use crate::common::util::*;
|
||||||
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::process::Output;
|
use std::process::{Output, Stdio};
|
||||||
|
|
||||||
fn make_broken_pipe() -> File {
|
fn make_broken_pipe() -> File {
|
||||||
use libc::c_int;
|
use libc::c_int;
|
||||||
|
@ -135,6 +135,7 @@ mod linux_only {
|
||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
let output = proc
|
let output = proc
|
||||||
.ignore_stdin_write_error()
|
.ignore_stdin_write_error()
|
||||||
|
.set_stdin(Stdio::piped())
|
||||||
.run_no_wait()
|
.run_no_wait()
|
||||||
.pipe_in_and_wait_with_output(content.as_bytes());
|
.pipe_in_and_wait_with_output(content.as_bytes());
|
||||||
|
|
||||||
|
|
|
@ -1105,6 +1105,7 @@ impl UCommand {
|
||||||
"{}",
|
"{}",
|
||||||
MULTIPLE_STDIN_MEANINGLESS
|
MULTIPLE_STDIN_MEANINGLESS
|
||||||
);
|
);
|
||||||
|
self.set_stdin(Stdio::piped());
|
||||||
self.bytes_into_stdin = Some(input.into());
|
self.bytes_into_stdin = Some(input.into());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -1170,8 +1171,7 @@ impl UCommand {
|
||||||
|
|
||||||
let command = self
|
let command = self
|
||||||
.raw
|
.raw
|
||||||
// TODO: use Stdio::null() as default to avoid accidental deadlocks ?
|
.stdin(self.stdin.take().unwrap_or_else(Stdio::null))
|
||||||
.stdin(self.stdin.take().unwrap_or_else(Stdio::piped))
|
|
||||||
.stdout(Stdio::from(output.try_clone().unwrap()))
|
.stdout(Stdio::from(output.try_clone().unwrap()))
|
||||||
.stderr(Stdio::from(output.try_clone().unwrap()));
|
.stderr(Stdio::from(output.try_clone().unwrap()));
|
||||||
captured_stdout = Some(output);
|
captured_stdout = Some(output);
|
||||||
|
@ -1197,8 +1197,7 @@ impl UCommand {
|
||||||
};
|
};
|
||||||
|
|
||||||
self.raw
|
self.raw
|
||||||
// TODO: use Stdio::null() as default to avoid accidental deadlocks ?
|
.stdin(self.stdin.take().unwrap_or_else(Stdio::null))
|
||||||
.stdin(self.stdin.take().unwrap_or_else(Stdio::piped))
|
|
||||||
.stdout(stdout)
|
.stdout(stdout)
|
||||||
.stderr(stderr)
|
.stderr(stderr)
|
||||||
};
|
};
|
||||||
|
@ -2696,7 +2695,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_uchild_when_pipe_in() {
|
fn test_uchild_when_pipe_in() {
|
||||||
let ts = TestScenario::new("cat");
|
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.pipe_in("content");
|
||||||
child.wait().unwrap().stdout_only("content").success();
|
child.wait().unwrap().stdout_only("content").success();
|
||||||
|
|
||||||
|
@ -2721,6 +2720,7 @@ mod tests {
|
||||||
|
|
||||||
let mut child = ts
|
let mut child = ts
|
||||||
.ucmd()
|
.ucmd()
|
||||||
|
.set_stdin(Stdio::piped())
|
||||||
.stderr_to_stdout()
|
.stderr_to_stdout()
|
||||||
.args(&["-riv", "a"])
|
.args(&["-riv", "a"])
|
||||||
.run_no_wait();
|
.run_no_wait();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue