Skip to content

Tail macos stdin ran from script fix #7844

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

hz2
Copy link
Contributor

@hz2 hz2 commented Apr 25, 2025

fixes #7763

causes test_stdin_redirect_dir_when_target_os_is_macos to fail, though may need more context on what this was testing.

thread 'test_tail::test_stdin_redirect_dir_when_target_os_is_macos' panicked at tests/by-util/test_tail.rs:340:10:
assertion failed: `(left == right)`

Diff < left / right > :
<tail: Is a directory
>tail: cannot open 'standard input' for reading: No such file or directory

Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/tee (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/timeout/timeout (passes in this run but fails in the 'main' branch)

@hz2 hz2 force-pushed the tail-macos-stdin-fix branch from 4e4bee7 to 1880010 Compare April 26, 2025 01:20
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/tee (passes in this run but fails in the 'main' branch)

@hz2 hz2 force-pushed the tail-macos-stdin-fix branch from ed4659c to abf730b Compare April 26, 2025 17:44
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/misc/tee (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)

@hz2 hz2 force-pushed the tail-macos-stdin-fix branch from 6864d8d to 4eb15ca Compare April 26, 2025 19:51
hz2 added 2 commits April 26, 2025 13:03
- introduce macOS-specific config guard
- added test for testing tail stdin when redirected (`>`) from file and
  when through a pipe (`|`)
@hz2 hz2 force-pushed the tail-macos-stdin-fix branch from 4eb15ca to 3c2e83a Compare April 26, 2025 20:05
@hz2
Copy link
Contributor Author

hz2 commented Apr 26, 2025

the comment above the test_stdin_redirect_dir_when_target_os_is_macos:

// On macOS path.is_dir() can be false for directories if it was a redirect,
// e.g. `$ tail < DIR. The library feature to detect the
// std::io::ErrorKind::IsADirectory isn't stable so we currently show the a wrong
// error message.
// FIXME: If `std::io::ErrorKind::IsADirectory` becomes stable or macos handles
//  redirected directories like linux show the correct message like in
//  `test_stdin_redirect_dir`

and is testing:

$ mkdir dir
$ tail < dir, $ tail - < dir
tail: error reading 'standard input': Is a directory

the differences between the error messages on what i see on my mac-m1 using GNU's tail and uutil's can be shown in the following changes to test_stdin_redirect_dir_when_target_os_is_macos:

    ts.ucmd()
        ...
        // .stderr_is("tail: stdin: Is a directory\n"); expected message macOS shows with GNU
        .stderr_is("tail: Is a directory\n"); // actual message we show
    ts.ucmd()
        ...
        // .stderr_is("tail: -: No such file or directory\n"); expected message macOS shows with GNU
        .stderr_is("tail: Is a directory\n"); // actual message we show

which should be handled but since functionality when running from a script is failing, this test should be ignored for now.

Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)

Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/misc/tee (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)

@hz2 hz2 marked this pull request as ready for review April 27, 2025 00:52
@sylvestre sylvestre requested a review from Copilot April 27, 2025 21:59
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses issue #7763 by disabling a failing test on macOS and adding an additional test to validate tail’s behavior when reading from a script via redirection and piping on Unix systems. It also adjusts the input handling logic in tail’s source to resolve discrepancies in behavior between macOS and other Unix platforms.

  • Disabled the test_stdin_redirect_dir_when_target_os_is_macos on macOS.
  • Added a new test, test_stdin_via_script_redirection_and_pipe, to cover script redirection and piping.
  • Updated the Input handling in paths.rs to return None on macOS and to canonicalize fd0 on non-macOS systems.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
tests/by-util/test_tail.rs Ignores a failing macOS test and adds a new test for script redirection.
src/uu/tail/src/paths.rs Modifies Input handling to differentiate between macOS and other Unix.
Comments suppressed due to low confidence (2)

tests/by-util/test_tail.rs:352

  • The new test is enabled under #[cfg(unix)] and may execute on macOS, where the behavior of tail for script redirection differs. Consider adding a more specific configuration guard (e.g., #[cfg(not(target_vendor = "apple"))]) if the expected output on macOS is different.
fn test_stdin_via_script_redirection_and_pipe() {

src/uu/tail/src/paths.rs:81

  • The macOS-specific branch returns None for Input handling. Verify that this change consistently supports both redirection and piping scenarios on macOS, or consider documenting the rationale to avoid future confusion.
#[cfg(target_os = "macos")]

@@ -324,6 +324,7 @@ fn test_stdin_redirect_dir() {
// `test_stdin_redirect_dir`
#[test]
#[cfg(target_vendor = "apple")]
#[ignore = "disabled until fixed"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer you fix that before we merge this PR :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in latest commit!

Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/misc/stdbuf (fails in this run but passes in the 'main' branch)
Congrats! The gnu test tests/rm/empty-inacc is no longer failing!

@@ -346,6 +346,54 @@ fn test_stdin_redirect_dir_when_target_os_is_macos() {
.stderr_is("tail: cannot open 'standard input' for reading: No such file or directory\n");
}

#[test]
#[cfg(unix)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems that it is failing on freebsd:

  ──── TRY 1 STDOUT:       coreutils::tests test_tail::test_stdin_via_script_redirection_and_pipe
  
  running 1 test
  bin: "/home/runner/work/coreutils/coreutils/target/debug/coreutils"
  write(default): /tmp/.tmpqaoG0W/file.txt
  run: sh -c ./test.sh < file.txt
  test test_tail::test_stdin_via_script_redirection_and_pipe ... FAILED
  
  failures:
  
  failures:
      test_tail::test_stdin_via_script_redirection_and_pipe
  
  test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 3718 filtered out; finished in 0.04s
  
  ──── TRY 1 STDERR:       coreutils::tests test_tail::test_stdin_via_script_redirection_and_pipe
  
  thread 'test_tail::test_stdin_via_script_redirection_and_pipe' panicked at tests/by-util/test_tail.rs:385:10:
  Command was expected to succeed. code: 127
  stdout = 
   stderr = sh: ./test.sh: not found
  
  stack backtrace:
     0: rust_begin_unwind
               at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library/std/src/panicking.rs:695:5
     1: core::panicking::panic_fmt
               at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library/core/src/panicking.rs:75:14
     2: uutests::util::CmdResult::success
               at ./tests/uutests/src/lib/util.rs:442:9
     3: uutests::util::UCommand::succeeds
               at ./tests/uutests/src/lib/util.rs:1929:9
     4: tests::test_tail::test_stdin_via_script_redirection_and_pipe
               at ./tests/by-util/test_tail.rs:381:5
     5: tests::test_tail::test_stdin_via_script_redirection_and_pipe::{{closure}}
               at ./tests/by-util/test_tail.rs:351:48
     6: core::ops::function::FnOnce::call_once
               at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library/core/src/ops/function.rs:250:5
     7: core::ops::function::FnOnce::call_once
               at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library/core/src/ops/function.rs:250:5
  note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for pointing this out, subtleties in FreeBSD

Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/stdbuf (passes in this run but fails in the 'main' branch)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tail does not read correctly from stdin when started from a script with redirection (but works with pipes)
2 participants