mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
tail: add test_follow_name_move_retry
* add fixes to pass test_follow_name_move_retry * fix test_follow_name_remove * bump notify to 5.0.0-pre.15 * adjust PollWatcher::with_delay -> PollWatcher::with_config
This commit is contained in:
parent
a62f71f93e
commit
6a7b6ccdbe
5 changed files with 127 additions and 45 deletions
|
@ -36,6 +36,7 @@ static FOLLOW_NAME_SHORT_EXP: &str = "follow_name_short.expected";
|
|||
static FOLLOW_NAME_EXP: &str = "follow_name.expected";
|
||||
|
||||
#[test]
|
||||
#[cfg(all(unix, not(target_os = "android")))] // FIXME: fix this test for Android
|
||||
fn test_stdin_default() {
|
||||
new_ucmd!()
|
||||
.pipe_in_fixture(FOOBAR_TXT)
|
||||
|
@ -45,6 +46,7 @@ fn test_stdin_default() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(all(unix, not(target_os = "android")))] // FIXME: fix this test for Android
|
||||
fn test_stdin_explicit() {
|
||||
new_ucmd!()
|
||||
.pipe_in_fixture(FOOBAR_TXT)
|
||||
|
@ -55,7 +57,7 @@ fn test_stdin_explicit() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(all(unix, not(target_os = "android")))] // FIXME: fix this test for Android
|
||||
fn test_stdin_redirect_file() {
|
||||
// $ echo foo > f
|
||||
|
||||
|
@ -389,6 +391,7 @@ fn test_follow_name_multiple() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(all(unix, not(target_os = "android")))] // FIXME: fix this test for Android
|
||||
fn test_follow_stdin_pipe() {
|
||||
new_ucmd!()
|
||||
.arg("-f")
|
||||
|
@ -493,6 +496,7 @@ fn test_bytes_single() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(all(unix, not(target_os = "android")))] // FIXME: fix this test for Android
|
||||
fn test_bytes_stdin() {
|
||||
new_ucmd!()
|
||||
.pipe_in_fixture(FOOBAR_TXT)
|
||||
|
@ -741,6 +745,7 @@ fn test_sleep_interval() {
|
|||
|
||||
/// Test for reading all but the first NUM bytes: `tail -c +3`.
|
||||
#[test]
|
||||
#[cfg(all(unix, not(target_os = "android")))] // FIXME: fix this test for Android
|
||||
fn test_positive_bytes() {
|
||||
new_ucmd!()
|
||||
.args(&["-c", "+3"])
|
||||
|
@ -751,6 +756,7 @@ fn test_positive_bytes() {
|
|||
|
||||
/// Test for reading all bytes, specified by `tail -c +0`.
|
||||
#[test]
|
||||
#[cfg(all(unix, not(target_os = "android")))] // FIXME: fix this test for Android
|
||||
fn test_positive_zero_bytes() {
|
||||
new_ucmd!()
|
||||
.args(&["-c", "+0"])
|
||||
|
@ -761,6 +767,7 @@ fn test_positive_zero_bytes() {
|
|||
|
||||
/// Test for reading all but the first NUM lines: `tail -n +3`.
|
||||
#[test]
|
||||
#[cfg(all(unix, not(target_os = "android")))] // FIXME: fix this test for Android
|
||||
fn test_positive_lines() {
|
||||
new_ucmd!()
|
||||
.args(&["-n", "+3"])
|
||||
|
@ -802,6 +809,7 @@ once
|
|||
|
||||
/// Test for reading all but the first NUM lines: `tail -3`.
|
||||
#[test]
|
||||
#[cfg(all(unix, not(target_os = "android")))] // FIXME: fix this test for Android
|
||||
fn test_obsolete_syntax_positive_lines() {
|
||||
new_ucmd!()
|
||||
.args(&["-3"])
|
||||
|
@ -812,6 +820,7 @@ fn test_obsolete_syntax_positive_lines() {
|
|||
|
||||
/// Test for reading all but the first NUM lines: `tail -n -10`.
|
||||
#[test]
|
||||
#[cfg(all(unix, not(target_os = "android")))] // FIXME: fix this test for Android
|
||||
fn test_small_file() {
|
||||
new_ucmd!()
|
||||
.args(&["-n -10"])
|
||||
|
@ -822,6 +831,7 @@ fn test_small_file() {
|
|||
|
||||
/// Test for reading all but the first NUM lines: `tail -10`.
|
||||
#[test]
|
||||
#[cfg(all(unix, not(target_os = "android")))] // FIXME: fix this test for Android
|
||||
fn test_obsolete_syntax_small_file() {
|
||||
new_ucmd!()
|
||||
.args(&["-10"])
|
||||
|
@ -832,6 +842,7 @@ fn test_obsolete_syntax_small_file() {
|
|||
|
||||
/// Test for reading all lines, specified by `tail -n +0`.
|
||||
#[test]
|
||||
#[cfg(all(unix, not(target_os = "android")))] // FIXME: fix this test for Android
|
||||
fn test_positive_zero_lines() {
|
||||
new_ucmd!()
|
||||
.args(&["-n", "+0"])
|
||||
|
@ -841,6 +852,7 @@ fn test_positive_zero_lines() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(all(unix, not(target_os = "android")))] // FIXME: fix this test for Android
|
||||
fn test_invalid_num() {
|
||||
new_ucmd!()
|
||||
.args(&["-c", "1024R", "emptyfile.txt"])
|
||||
|
@ -878,6 +890,7 @@ fn test_invalid_num() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(all(unix, not(target_os = "android")))] // FIXME: fix this test for Android
|
||||
fn test_num_with_undocumented_sign_bytes() {
|
||||
// tail: '-' is not documented (8.32 man pages)
|
||||
// head: '+' is not documented (8.32 man pages)
|
||||
|
@ -1425,15 +1438,21 @@ fn test_follow_name_remove() {
|
|||
at.copy(source, source_copy);
|
||||
|
||||
let expected_stdout = at.read(FOLLOW_NAME_SHORT_EXP);
|
||||
let expected_stderr = format!(
|
||||
"{}: {}: No such file or directory\n{0}: no files remaining\n",
|
||||
ts.util_name, source_copy
|
||||
);
|
||||
let expected_stderr = [
|
||||
format!(
|
||||
"{}: {}: No such file or directory\n{0}: no files remaining\n",
|
||||
ts.util_name, source_copy
|
||||
),
|
||||
format!(
|
||||
"{}: {}: No such file or directory\n",
|
||||
ts.util_name, source_copy
|
||||
),
|
||||
];
|
||||
|
||||
let delay = 2000;
|
||||
let mut args = vec!["--follow=name", source_copy, "--use-polling"];
|
||||
|
||||
for _ in 0..2 {
|
||||
for i in 0..2 {
|
||||
at.copy(source, source_copy);
|
||||
let mut p = ts.ucmd().set_stdin(Stdio::null()).args(&args).run_no_wait();
|
||||
|
||||
|
@ -1445,7 +1464,7 @@ fn test_follow_name_remove() {
|
|||
|
||||
let (buf_stdout, buf_stderr) = take_stdout_stderr(&mut p);
|
||||
assert_eq!(buf_stdout, expected_stdout);
|
||||
assert_eq!(buf_stderr, expected_stderr);
|
||||
assert_eq!(buf_stderr, expected_stderr[i]);
|
||||
|
||||
args.pop();
|
||||
}
|
||||
|
@ -1597,7 +1616,7 @@ fn test_follow_name_move_create() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
#[cfg(all(unix, not(target_os = "android")))] // FIXME: fix this test for Android
|
||||
fn test_follow_name_move() {
|
||||
// This test triggers a move event while `tail --follow=name logfile` is running.
|
||||
// ((sleep 2 && mv logfile backup &)>/dev/null 2>&1 &) ; tail --follow=name logfile
|
||||
|
@ -1638,6 +1657,59 @@ fn test_follow_name_move() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(all(unix, not(target_os = "android")))] // FIXME: fix this test for Android
|
||||
fn test_follow_name_move_retry() {
|
||||
// Similar to test_follow_name_move but with `--retry` (`-F`)
|
||||
// This test triggers two move/rename events while `tail --follow=name --retry logfile` is running.
|
||||
|
||||
let ts = TestScenario::new(util_name!());
|
||||
let at = &ts.fixtures;
|
||||
|
||||
let source = FOLLOW_NAME_TXT;
|
||||
let backup = "backup";
|
||||
|
||||
let expected_stderr = format!(
|
||||
"{0}: '{1}' has become inaccessible: No such file or directory\n\
|
||||
{0}: '{1}' has appeared; following new file\n",
|
||||
ts.util_name, source
|
||||
);
|
||||
let expected_stdout = "tailed\nnew content\n";
|
||||
|
||||
let mut args = vec!["--follow=name", "--retry", source, "--use-polling"];
|
||||
|
||||
#[allow(clippy::needless_range_loop)]
|
||||
for _ in 0..2 {
|
||||
at.touch(source);
|
||||
let mut p = ts.ucmd().set_stdin(Stdio::null()).args(&args).run_no_wait();
|
||||
|
||||
sleep(Duration::from_millis(1000));
|
||||
at.append(source, "tailed\n");
|
||||
|
||||
sleep(Duration::from_millis(2000));
|
||||
// with --follow=name, tail should stop monitoring the renamed file
|
||||
at.rename(source, backup);
|
||||
sleep(Duration::from_millis(4000));
|
||||
|
||||
// overwrite backup while it's not monitored
|
||||
at.truncate(backup, "new content\n");
|
||||
sleep(Duration::from_millis(500));
|
||||
// move back, tail should pick this up and print new content
|
||||
at.rename(backup, source);
|
||||
sleep(Duration::from_millis(4000));
|
||||
|
||||
p.kill().unwrap();
|
||||
|
||||
let (buf_stdout, buf_stderr) = take_stdout_stderr(&mut p);
|
||||
dbg!(&buf_stdout, &buf_stderr);
|
||||
assert_eq!(buf_stdout, expected_stdout);
|
||||
assert_eq!(buf_stderr, expected_stderr);
|
||||
|
||||
at.remove(source);
|
||||
args.pop();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn test_follow_inotify_only_regular() {
|
||||
|
@ -1685,11 +1757,13 @@ fn test_no_such_file() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(all(unix, not(target_os = "android")))] // FIXME: fix this test for Android
|
||||
fn test_no_trailing_newline() {
|
||||
new_ucmd!().pipe_in("x").succeeds().stdout_only("x");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(all(unix, not(target_os = "android")))] // FIXME: fix this test for Android
|
||||
fn test_lines_zero_terminated() {
|
||||
new_ucmd!()
|
||||
.args(&["-z", "-n", "2"])
|
||||
|
@ -1704,6 +1778,7 @@ fn test_lines_zero_terminated() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(all(unix, not(target_os = "android")))] // FIXME: fix this test for Android
|
||||
fn test_presume_input_pipe_default() {
|
||||
new_ucmd!()
|
||||
.arg("---presume-input-pipe")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue