Skip to content

Commit

Permalink
tests/tail: Reactivate and adjust disabled tests (in pr uutils#4135) …
Browse files Browse the repository at this point in the history
…to reflect current development state.
  • Loading branch information
Joining7943 committed Feb 18, 2023
1 parent 0e36b02 commit ded391d
Showing 1 changed file with 38 additions and 59 deletions.
97 changes: 38 additions & 59 deletions tests/by-util/test_tail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::common::random::*;
use crate::common::util::*;
use pretty_assertions::assert_eq;
use rand::distributions::Alphanumeric;
use regex::Regex;
use rstest::rstest;
use std::char::from_digit;
use std::fs::File;
Expand Down Expand Up @@ -3482,19 +3483,18 @@ fn test_when_argument_file_is_a_symlink_to_directory_then_error() {
// TODO: make this work on windows
#[test]
#[cfg(unix)]
#[cfg(disabled_until_fixed)]
fn test_when_argument_file_is_a_faulty_symlink_then_error() {
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;

at.symlink_file("self", "self");

#[cfg(all(not(target_env = "musl"), not(target_os = "android")))]
let expected = "tail: cannot open 'self' for reading: Too many levels of symbolic links";
let expected = "tail: cannot open 'self' for reading: Too many levels of symbolic links\n";
#[cfg(all(not(target_env = "musl"), target_os = "android"))]
let expected = "tail: cannot open 'self' for reading: Too many symbolic links encountered";
let expected = "tail: cannot open 'self' for reading: Too many symbolic links encountered\n";
#[cfg(all(target_env = "musl", not(target_os = "android")))]
let expected = "tail: cannot open 'self' for reading: Symbolic link loop";
let expected = "tail: cannot open 'self' for reading: Symbolic link loop\n";

ts.ucmd()
.arg("self")
Expand All @@ -3504,7 +3504,7 @@ fn test_when_argument_file_is_a_faulty_symlink_then_error() {

at.symlink_file("missing", "broken");

let expected = "tail: cannot open 'broken' for reading: No such file or directory";
let expected = "tail: cannot open 'broken' for reading: No such file or directory\n";
ts.ucmd()
.arg("broken")
.fails()
Expand Down Expand Up @@ -3572,7 +3572,6 @@ fn test_when_argument_file_is_non_existent_unix_socket_address_then_error() {
}

#[test]
#[cfg(disabled_until_fixed)]
fn test_when_argument_files_are_simple_combinations_of_stdin_and_regular_file() {
let scene = TestScenario::new(util_name!());
let fixtures = &scene.fixtures;
Expand Down Expand Up @@ -3603,7 +3602,7 @@ fn test_when_argument_files_are_simple_combinations_of_stdin_and_regular_file()
.success()
.stdout_only(expected);

let expected = "==> standard input <==\n\
let expected = "==> empty <==\n\
\n\
==> standard input <==\n";
scene
Expand Down Expand Up @@ -3674,7 +3673,6 @@ fn test_when_argument_files_are_simple_combinations_of_stdin_and_regular_file()
}

#[test]
#[cfg(disabled_until_fixed)]
fn test_when_argument_files_are_triple_combinations_of_fifo_pipe_and_regular_file() {
let scene = TestScenario::new(util_name!());
let fixtures = &scene.fixtures;
Expand All @@ -3697,7 +3695,6 @@ fn test_when_argument_files_are_triple_combinations_of_fifo_pipe_and_regular_fil
.stdout_only(expected)
.success();

runner.reset();
let expected = "==> standard input <==\n\
\n\
==> empty <==\n\
Expand All @@ -3713,9 +3710,9 @@ fn test_when_argument_files_are_triple_combinations_of_fifo_pipe_and_regular_fil
.success();

let expected = "==> standard input <==\n\
\n\
==> empty <==\n\
\n\
pipe data\n\
==> data <==\n\
file data\n\
==> standard input <==\n";
scene
.ucmd()
Expand All @@ -3729,25 +3726,26 @@ fn test_when_argument_files_are_triple_combinations_of_fifo_pipe_and_regular_fil
// print the fifo twice. This matches the behavior, if only the pipe is present without fifo
// (See test above). Note that for example a zsh shell prints the pipe data and has therefore
// different output from the sh shell (or cmd shell on windows).

//
// windows: tail returns with success although there is an error message present (on some
// windows systems). This error message comes from `echo` (the line ending `\r\n` indicates that
// too) which cannot write to the pipe because tail finished before echo was able to write to
// the pipe. Seems that windows `cmd` (like posix shells) ignores pipes when a fifo is present.
// This is actually the wished behavior and the test therefore succeeds.
// too) which cannot write to the pipe. This is actually the wished behavior and the test
// therefore succeeds in such cases.
//
// [`CmdResult::stdout_matches`] trims the stdout, so we ignore the final newlines in the regex.
#[cfg(windows)]
let expected = "==> standard input <==\n\
let expected = "^==> standard input <==\n\
fifo data\n\
==> data <==\n\
file data\n\
==> standard input <==\n\
(The process tried to write to a nonexistent pipe.\r\n)?";
==> standard input <==(\n)?\
(The process tried to write to a nonexistent pipe.(\r\n)?)?$";
#[cfg(unix)]
let expected = "==> standard input <==\n\
let expected = "^==> standard input <==\n\
fifo data\n\
==> data <==\n\
file data\n\
==> standard input <==\n";
==> standard input <==(\n)?$";

#[cfg(windows)]
let cmd = ["cmd", "/C"];
Expand All @@ -3761,8 +3759,9 @@ fn test_when_argument_files_are_triple_combinations_of_fifo_pipe_and_regular_fil
"echo pipe data | {} tail -c +0 - data - < fifo",
scene.bin_path.display(),
))
.stderr_to_stdout()
.run()
.stdout_only(expected)
.stdout_matches(&Regex::new(expected).unwrap())
.success();

let expected = "==> standard input <==\n\
Expand Down Expand Up @@ -4064,27 +4063,27 @@ fn test_args_when_settings_check_warnings_follow_indefinitely_then_no_warning()
.make_assertion_with_delay(delay)
.with_current_output()
.stdout_only(expected_stdout);
}

let expected_stdout = format!(
"==> standard input <==\n\
let expected_stdout = format!(
"==> standard input <==\n\
{fifo_data}\n\
==> {file_name} <==\n\
{file_data}"
);
let mut child = scene
.ucmd()
.args(&["--follow=descriptor", "--pid=0", "-", file_name])
.set_stdin(File::open(fixtures.plus(fifo_name)).unwrap())
.stderr_to_stdout()
.run_no_wait();
);
let mut child = scene
.ucmd()
.args(&["--follow=descriptor", "--pid=0", "-", file_name])
.set_stdin(File::open(fixtures.plus(fifo_name)).unwrap())
.stderr_to_stdout()
.run_no_wait();

child.make_assertion_with_delay(delay).is_alive();
child
.kill()
.make_assertion_with_delay(delay)
.with_current_output()
.stdout_only(expected_stdout);
}
child.make_assertion_with_delay(delay).is_alive();
child
.kill()
.make_assertion_with_delay(delay)
.with_current_output()
.stdout_only(expected_stdout);
}

/// The expected test outputs come from gnu's tail.
Expand Down Expand Up @@ -4357,28 +4356,8 @@ fn test_args_when_directory_given_shorthand_big_f_together_with_retry() {
/// ==> /absolute/path/to/data <==
/// <file datasame data
/// >file data
///
/// Fails on windows with
/// Diff < left / right > :
// ==> data <==
// file data
// ==> \\?\C:\Users\runneradmin\AppData\Local\Temp\.tmpi6lNnX\data <==
// >file data
// <
//
// Fails on freebsd with
// Diff < left / right > :
// ==> data <==
// file data
// ==> /tmp/.tmpZPXPlS/data <==
// >file data
// <
#[test]
#[cfg(all(
not(target_vendor = "apple"),
not(target_os = "windows"),
not(target_os = "freebsd")
))]
#[cfg(all(not(target_vendor = "apple")))]
fn test_follow_when_files_are_pointing_to_same_relative_file_and_file_stays_same_size() {
let scene = TestScenario::new(util_name!());
let fixtures = &scene.fixtures;
Expand Down

0 comments on commit ded391d

Please sign in to comment.