1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

tests: Use UChild in tests. Rename run_no_wait_child to run_no_wait and return UChild

tests/tail:
* test_stdin_redirect_file:. Test fails now when assert_alive()!
The follow test `tail -f < file` where file's content is `foo` fails with:
    Assertion failed. Expected 'tail' to be running but exited with status=exit status: 0

I also tried on the command line and can confirm that tail isn't runnning when following by
descriptor. The test is deactivated until the implementation is fixed.

* test_follow_stdin_descriptor
* test_follow_stdin_explicit_indefinitely.
* test_follow_single
* test_follow_non_utf8_bytes
* test_follow_multiple
* test_follow_name_multiple
* test_follow_invalid_pid
* test_single_big_args
* test_retry3
* test_retry4
* test_retry5
* test_retry7
* test_retry8
* test_retry9
* test_follow_descriptor_vs_rename1
* test_follow_descriptor_vs_rename2
* test_follow_name_retry_headers
* test_follow_name_remove
* test_follow_name_truncate1
* test_follow_name_truncate2
* test_follow_name_truncate3
* test_follow_name_truncate4
* test_follow_truncate_fast
* test_follow_name_move_create1
* test_follow_name_move_create2
* test_follow_name_move1
* test_follow_name_move2
* test_follow_name_move_retry1
* test_follow_name_move_retry2
* test_follow_inotify_only_regular
* test_fifo
* test_illegal_seek

tests/cat:
* test_dev_full
* test_dev_full_show_all
* test_dev_random
* test_fifo_symlink

tests/dd:
* test_random_73k_test_lazy_fullblock
* test_sync_delayed_reader

tests/factor:
* test_parallel

tests/rm:
* test_rm_force_prompts_order
* test_rm_descend_directory
* test_rm_prompts

tests/seq:
* the helper run method

tests/sort:
* test_sigpipe_panic

tests/tee:
* the helper run_tee method

tests/tty:
* test_tty module

tests/yes:
* the helper run method
This commit is contained in:
Joining7943 2022-11-18 01:25:43 +01:00
parent 040a5e8301
commit 982fb682e9
11 changed files with 519 additions and 474 deletions

View file

@ -357,8 +357,6 @@ fn test_rm_interactive_never() {
fn test_rm_descend_directory() {
// This test descends into each directory and deletes the files and folders inside of them
// This test will have the rm process asks 6 question and us answering Y to them will delete all the files and folders
use std::io::Write;
use std::process::Child;
// Needed for talking with stdin on platforms where CRLF or LF matters
const END_OF_LINE: &str = if cfg!(windows) { "\r\n" } else { "\n" };
@ -375,24 +373,15 @@ fn test_rm_descend_directory() {
at.touch(file_1);
at.touch(file_2);
let mut child: 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.write_in(yes.as_bytes()).unwrap();
child.write_in(yes.as_bytes()).unwrap();
child.write_in(yes.as_bytes()).unwrap();
child.write_in(yes.as_bytes()).unwrap();
child.write_in(yes.as_bytes()).unwrap();
// Needed so that we can talk to the rm program
let mut child_stdin = child.stdin.take().unwrap();
child_stdin.write_all(yes.as_bytes()).unwrap();
child_stdin.flush().unwrap();
child_stdin.write_all(yes.as_bytes()).unwrap();
child_stdin.flush().unwrap();
child_stdin.write_all(yes.as_bytes()).unwrap();
child_stdin.flush().unwrap();
child_stdin.write_all(yes.as_bytes()).unwrap();
child_stdin.flush().unwrap();
child_stdin.write_all(yes.as_bytes()).unwrap();
child_stdin.flush().unwrap();
child_stdin.write_all(yes.as_bytes()).unwrap();
child_stdin.flush().unwrap();
child.wait_with_output().unwrap();
child.wait().unwrap();
assert!(!at.dir_exists("a/b"));
assert!(!at.dir_exists("a"));
@ -404,7 +393,6 @@ fn test_rm_descend_directory() {
#[test]
fn test_rm_prompts() {
use std::io::Write;
use std::process::Child;
// Needed for talking with stdin on platforms where CRLF or LF matters
const END_OF_LINE: &str = if cfg!(windows) { "\r\n" } else { "\n" };
@ -457,21 +445,15 @@ fn test_rm_prompts() {
.arg(file_2)
.succeeds();
let mut child: Child = scene.ucmd().arg("-ri").arg("a").run_no_wait();
let mut child_stdin = child.stdin.take().unwrap();
let mut child = scene.ucmd().arg("-ri").arg("a").run_no_wait();
for _ in 0..9 {
child_stdin.write_all(yes.as_bytes()).unwrap();
child_stdin.flush().unwrap();
child.write_in(yes.as_bytes()).unwrap();
}
let output = child.wait_with_output().unwrap();
let result = child.wait().unwrap();
let mut trimmed_output = Vec::new();
for string in String::from_utf8(output.stderr)
.expect("Couldn't convert output.stderr to string")
.split("rm: ")
{
for string in result.stderr_str().split("rm: ") {
if !string.is_empty() {
let trimmed_string = format!("rm: {}", string).trim().to_string();
trimmed_output.push(trimmed_string);
@ -491,9 +473,6 @@ fn test_rm_prompts() {
#[test]
fn test_rm_force_prompts_order() {
use std::io::Write;
use std::process::Child;
// Needed for talking with stdin on platforms where CRLF or LF matters
const END_OF_LINE: &str = if cfg!(windows) { "\r\n" } else { "\n" };
@ -507,15 +486,11 @@ fn test_rm_force_prompts_order() {
at.touch(empty_file);
// This should cause rm to prompt to remove regular empty file
let mut child: 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();
let mut child_stdin = child.stdin.take().unwrap();
child_stdin.write_all(yes.as_bytes()).unwrap();
child_stdin.flush().unwrap();
let output = child.wait_with_output().unwrap();
let string_output =
String::from_utf8(output.stderr).expect("Couldn't convert output.stderr to string");
let result = child.wait().unwrap();
let string_output = result.stderr_str();
assert_eq!(
string_output.trim(),
"rm: remove regular empty file 'empty'?"