Skip to content

Commit

Permalink
tests/tail: Fix error messsages for directory errors on windows targets
Browse files Browse the repository at this point in the history
  • Loading branch information
Joining7943 committed Apr 9, 2023
1 parent 3cdbed5 commit 6328da7
Showing 1 changed file with 65 additions and 21 deletions.
86 changes: 65 additions & 21 deletions tests/by-util/test_tail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ const INVALID_UTF8: u8 = 0x80;
#[cfg(windows)]
const INVALID_UTF16: u16 = 0xD800;

/// Copied this from test_tee. test_tee uses this on linux targets only. This method doesn't work on
/// macos targets.
#[cfg(all(unix, not(target_vendor = "apple")))]
/// Copied this from test_tee. test_tee uses this on linux targets only.
#[cfg(target_os = "linux")]
fn make_broken_pipe() -> File {
use libc::c_int;
use std::os::unix::io::FromRawFd;
Expand Down Expand Up @@ -546,11 +545,19 @@ fn test_follow_multiple_untailable() {

// FIXME: DIR1 and DIR2 need to be in single quotes
let expected_stdout = "==> DIR1 <==\n\n==> DIR2 <==\n";
#[cfg(not(windows))]
let expected_stderr = "tail: error reading 'DIR1': Is a directory\n\
tail: DIR1: cannot follow end of this type of file; giving up on this name\n\
tail: error reading 'DIR2': Is a directory\n\
tail: DIR2: cannot follow end of this type of file; giving up on this name\n\
tail: no files remaining\n";
#[cfg(windows)]
let expected_stderr =
"tail: error reading 'DIR1': An operation is not supported on a directory.\n\
tail: DIR1: cannot follow end of this type of file; giving up on this name\n\
tail: error reading 'DIR2': An operation is not supported on a directory.\n\
tail: DIR2: cannot follow end of this type of file; giving up on this name\n\
tail: no files remaining\n";

let (at, mut ucmd) = at_and_ucmd!();
at.mkdir("DIR1");
Expand Down Expand Up @@ -872,10 +879,11 @@ fn test_multiple_input_quiet_flag_overrides_verbose_flag_for_suppressing_headers
fn test_dir() {
let (at, mut ucmd) = at_and_ucmd!();
at.mkdir("DIR");
ucmd.arg("DIR")
.run()
.stderr_is("tail: error reading 'DIR': Is a directory\n")
.code_is(1);
#[cfg(not(windows))]
let expected = "tail: error reading 'DIR': Is a directory\n";
#[cfg(windows)]
let expected = "tail: error reading 'DIR': An operation is not supported on a directory.\n";
ucmd.arg("DIR").run().stderr_is(expected).code_is(1);
}

#[test]
Expand All @@ -884,18 +892,23 @@ fn test_dir_follow() {
let at = &ts.fixtures;
at.mkdir("DIR");

#[cfg(not(windows))]
let expected = "tail: error reading 'DIR': Is a directory\n\
tail: DIR: cannot follow end of this type of file; giving up on this name\n\
tail: no files remaining\n";
#[cfg(windows)]
let expected = "tail: error reading 'DIR': An operation is not supported on a directory.\n\
tail: DIR: cannot follow end of this type of file; giving up on this name\n\
tail: no files remaining\n";

// FIXME: DIR must be single quoted
for mode in &["--follow=descriptor", "--follow=name"] {
ts.ucmd()
.arg(mode)
.arg("DIR")
.run()
.no_stdout()
.stderr_is(
"tail: error reading 'DIR': Is a directory\n\
tail: DIR: cannot follow end of this type of file; giving up on this name\n\
tail: no files remaining\n",
)
.stderr_is(expected)
.code_is(1);
}
}
Expand All @@ -905,18 +918,22 @@ fn test_dir_follow_retry() {
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
at.mkdir("DIR");
// FIXME: DIR must be single quoted
#[cfg(not(windows))]
let expected = "tail: warning: --retry only effective for the initial open\n\
tail: error reading 'DIR': Is a directory\n\
tail: DIR: cannot follow end of this type of file\n\
tail: no files remaining\n";
#[cfg(windows)]
let expected = "tail: warning: --retry only effective for the initial open\n\
tail: error reading 'DIR': An operation is not supported on a directory.\n\
tail: DIR: cannot follow end of this type of file\n\
tail: no files remaining\n";
ts.ucmd()
.arg("--follow=descriptor")
.arg("--retry")
.arg("DIR")
.run()
.stderr_is(
"tail: warning: --retry only effective for the initial open\n\
tail: error reading 'DIR': Is a directory\n\
tail: DIR: cannot follow end of this type of file\n\
tail: no files remaining\n",
)
.stderr_is(expected)
.code_is(1);
}

Expand Down Expand Up @@ -3405,10 +3422,16 @@ fn test_when_follow_retry_given_redirected_stdin_from_directory_then_correct_err
let at = &ts.fixtures;
at.mkdir("dir");

#[cfg(not(windows))]
let expected = "tail: warning: --retry only effective for the initial open\n\
tail: error reading 'standard input': Is a directory\n\
tail: 'standard input': cannot follow end of this type of file\n\
tail: no files remaining\n";
#[cfg(windows)]
let expected = "tail: warning: --retry only effective for the initial open\n\
tail: error reading 'standard input': An operation is not supported on a directory.\n\
tail: 'standard input': cannot follow end of this type of file\n\
tail: no files remaining\n";
ts.ucmd()
.set_stdin(File::open(at.plus("dir")).unwrap())
.args(&["-f", "--retry"])
Expand All @@ -3423,7 +3446,10 @@ fn test_when_argument_file_is_a_directory() {
let at = &ts.fixtures;
at.mkdir("dir");

#[cfg(not(windows))]
let expected = "tail: error reading 'dir': Is a directory\n";
#[cfg(windows)]
let expected = "tail: error reading 'dir': An operation is not supported on a directory.\n";
ts.ucmd()
.arg("dir")
.fails()
Expand Down Expand Up @@ -4331,11 +4357,18 @@ fn test_args_when_directory_given_shorthand_big_f_together_with_retry() {

let dirname = "dir";
fixtures.mkdir(dirname);
#[cfg(not(windows))]
let expected_stderr = format!(
"tail: error reading '{0}': Is a directory\n\
tail: {0}: cannot follow end of this type of file\n",
dirname
);
#[cfg(windows)]
let expected_stderr = format!(
"tail: error reading '{0}': An operation is not supported on a directory.\n\
tail: {0}: cannot follow end of this type of file\n",
dirname
);

let mut child = scene.ucmd().args(&["-F", "--retry", "dir"]).run_no_wait();

Expand Down Expand Up @@ -4759,11 +4792,15 @@ fn test_when_stdin_is_bad_file_descriptor(#[case] args: &[&str]) {
let at = &ts.fixtures;
// Opens the file in write only mode and leads to the bad file descriptor error when used as stdin
let file = File::create(at.plus_as_string("name")).unwrap();
#[cfg(not(windows))]
let expected = "tail: error reading 'standard input': Bad file descriptor\n";
#[cfg(windows)]
let expected = "tail: error reading 'standard input': Permission denied\n";
ts.ucmd()
.args(args)
.set_stdin(file)
.run()
.stderr_only("tail: error reading 'standard input': Bad file descriptor\n");
.stderr_only(expected);
}

#[test]
Expand All @@ -4781,11 +4818,18 @@ fn test_when_follow_two_files_and_stdin_is_bad_file_descriptor() {
// instead of:
// tail: cannot fstat 'standard input': Bad file descriptor
// tail: error reading 'standard input': Bad file descriptor
#[cfg(not(windows))]
let expected_stdout = "==> standard input <==\n\
tail: error reading 'standard input': Bad file descriptor\n\
\n\
==> good <==\n\
good content";
#[cfg(windows)]
let expected_stdout = "==> standard input <==\n\
tail: error reading 'standard input': Permission denied\n\
\n\
==> good <==\n\
good content";

let mut child = ts
.ucmd()
Expand All @@ -4811,7 +4855,7 @@ fn test_when_follow_two_files_and_stdin_is_bad_file_descriptor() {
#[rstest]
#[case::when_not_follow(&["-c", "+0", "-"])]
#[case::when_follow(&["-c", "+0", "-f", "-"])]
#[cfg(all(unix, not(target_vendor = "apple")))]
#[cfg(target_os = "linux")]
fn test_when_stdout_is_broken_pipe(#[case] args: &[&str]) {
new_ucmd!()
.args(args)
Expand Down

0 comments on commit 6328da7

Please sign in to comment.