mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
tests/util: Improve UChild. Cleanup redundant functions in util.rs.
A short summary of changes: * Add some basic tests for UChild and the run methods. * Try more often in a fixed interval to create the tempfile for CapturedOutput. * Fix drop order of struct fields for better cleanup of temporary files/dirs. * Mark UChild::wait_with_output and UChild::pipe_in_and_wait_with_output deprecated * Make CapturedOutput private * Panic in stdout_all, stdout_all_bytes etc. if output is not captured. * Rename some methods, refactor, clean up, fix documentation, add try_... methods
This commit is contained in:
parent
982fb682e9
commit
4f54eedb74
5 changed files with 549 additions and 278 deletions
|
@ -374,12 +374,12 @@ fn test_rm_descend_directory() {
|
||||||
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().arg("-ri").arg("a").run_no_wait();
|
||||||
child.write_in(yes.as_bytes()).unwrap();
|
child.try_write_in(yes.as_bytes()).unwrap();
|
||||||
child.write_in(yes.as_bytes()).unwrap();
|
child.try_write_in(yes.as_bytes()).unwrap();
|
||||||
child.write_in(yes.as_bytes()).unwrap();
|
child.try_write_in(yes.as_bytes()).unwrap();
|
||||||
child.write_in(yes.as_bytes()).unwrap();
|
child.try_write_in(yes.as_bytes()).unwrap();
|
||||||
child.write_in(yes.as_bytes()).unwrap();
|
child.try_write_in(yes.as_bytes()).unwrap();
|
||||||
child.write_in(yes.as_bytes()).unwrap();
|
child.try_write_in(yes.as_bytes()).unwrap();
|
||||||
|
|
||||||
child.wait().unwrap();
|
child.wait().unwrap();
|
||||||
|
|
||||||
|
@ -447,7 +447,7 @@ fn test_rm_prompts() {
|
||||||
|
|
||||||
let mut child = scene.ucmd().arg("-ri").arg("a").run_no_wait();
|
let mut child = scene.ucmd().arg("-ri").arg("a").run_no_wait();
|
||||||
for _ in 0..9 {
|
for _ in 0..9 {
|
||||||
child.write_in(yes.as_bytes()).unwrap();
|
child.try_write_in(yes.as_bytes()).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = child.wait().unwrap();
|
let result = child.wait().unwrap();
|
||||||
|
@ -487,7 +487,7 @@ fn test_rm_force_prompts_order() {
|
||||||
|
|
||||||
// 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().arg("-fi").arg(empty_file).run_no_wait();
|
||||||
child.write_in(yes.as_bytes()).unwrap();
|
child.try_write_in(yes.as_bytes()).unwrap();
|
||||||
|
|
||||||
let result = child.wait().unwrap();
|
let result = child.wait().unwrap();
|
||||||
let string_output = result.stderr_str();
|
let string_output = result.stderr_str();
|
||||||
|
|
|
@ -512,7 +512,7 @@ fn test_follow_non_utf8_bytes() {
|
||||||
.run_no_wait();
|
.run_no_wait();
|
||||||
|
|
||||||
child
|
child
|
||||||
.make_assertion_with_delay(100)
|
.make_assertion_with_delay(500)
|
||||||
.is_alive()
|
.is_alive()
|
||||||
.with_current_output()
|
.with_current_output()
|
||||||
.stdout_only_fixture("foobar_single_default.expected");
|
.stdout_only_fixture("foobar_single_default.expected");
|
||||||
|
@ -712,7 +712,7 @@ fn test_follow_with_pid() {
|
||||||
.run_no_wait();
|
.run_no_wait();
|
||||||
|
|
||||||
child
|
child
|
||||||
.make_assertion_with_delay(100)
|
.make_assertion_with_delay(500)
|
||||||
.is_alive()
|
.is_alive()
|
||||||
.with_current_output()
|
.with_current_output()
|
||||||
.stdout_only_fixture("foobar_follow_multiple.expected");
|
.stdout_only_fixture("foobar_follow_multiple.expected");
|
||||||
|
@ -1392,9 +1392,8 @@ fn test_retry5() {
|
||||||
at.mkdir(missing);
|
at.mkdir(missing);
|
||||||
p.delay(delay);
|
p.delay(delay);
|
||||||
|
|
||||||
p.make_assertion().is_not_alive();
|
p.make_assertion()
|
||||||
p.kill()
|
.is_not_alive()
|
||||||
.make_assertion()
|
|
||||||
.with_all_output()
|
.with_all_output()
|
||||||
.stderr_only(expected_stderr)
|
.stderr_only(expected_stderr)
|
||||||
.failure();
|
.failure();
|
||||||
|
@ -1895,9 +1894,8 @@ fn test_follow_name_remove() {
|
||||||
p.delay(delay);
|
p.delay(delay);
|
||||||
|
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
p.make_assertion().is_not_alive();
|
p.make_assertion()
|
||||||
p.kill()
|
.is_not_alive()
|
||||||
.make_assertion()
|
|
||||||
.with_all_output()
|
.with_all_output()
|
||||||
.stdout_is(&expected_stdout)
|
.stdout_is(&expected_stdout)
|
||||||
.stderr_is(&expected_stderr[i])
|
.stderr_is(&expected_stderr[i])
|
||||||
|
@ -2299,9 +2297,8 @@ fn test_follow_name_move1() {
|
||||||
.stderr_is(&expected_stderr[i])
|
.stderr_is(&expected_stderr[i])
|
||||||
.stdout_is(&expected_stdout);
|
.stdout_is(&expected_stdout);
|
||||||
} else {
|
} else {
|
||||||
p.make_assertion().is_not_alive();
|
p.make_assertion()
|
||||||
p.kill()
|
.is_not_alive()
|
||||||
.make_assertion()
|
|
||||||
.with_all_output()
|
.with_all_output()
|
||||||
.stderr_is(&expected_stderr[i])
|
.stderr_is(&expected_stderr[i])
|
||||||
.stdout_is(&expected_stdout)
|
.stdout_is(&expected_stdout)
|
||||||
|
|
|
@ -131,6 +131,8 @@ mod linux_only {
|
||||||
|
|
||||||
fn run_tee(proc: &mut UCommand) -> (String, Output) {
|
fn run_tee(proc: &mut UCommand) -> (String, Output) {
|
||||||
let content = (1..=100000).map(|x| format!("{}\n", x)).collect::<String>();
|
let content = (1..=100000).map(|x| format!("{}\n", x)).collect::<String>();
|
||||||
|
|
||||||
|
#[allow(deprecated)]
|
||||||
let output = proc
|
let output = proc
|
||||||
.run_no_wait()
|
.run_no_wait()
|
||||||
.pipe_in_and_wait_with_output(content.as_bytes());
|
.pipe_in_and_wait_with_output(content.as_bytes());
|
||||||
|
|
|
@ -21,6 +21,8 @@ fn run(args: &[&str], expected: &[u8]) {
|
||||||
let mut child = cmd.args(args).set_stdout(Stdio::piped()).run_no_wait();
|
let mut child = cmd.args(args).set_stdout(Stdio::piped()).run_no_wait();
|
||||||
let buf = child.stdout_exact_bytes(expected.len());
|
let buf = child.stdout_exact_bytes(expected.len());
|
||||||
child.close_stdout();
|
child.close_stdout();
|
||||||
|
|
||||||
|
#[allow(deprecated)]
|
||||||
check_termination(&child.wait_with_output().unwrap().status);
|
check_termination(&child.wait_with_output().unwrap().status);
|
||||||
assert_eq!(buf.as_slice(), expected);
|
assert_eq!(buf.as_slice(), expected);
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue