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

tail: fix handling of PermissionDenied Error

* add tests for opening unreadable files
This commit is contained in:
Jan Scheer 2022-05-26 12:53:50 +02:00
parent 6bd9a1d537
commit 4bbf708c81
No known key found for this signature in database
GPG key ID: C62AD4C29E2B9828
2 changed files with 86 additions and 32 deletions

View file

@ -97,6 +97,46 @@ fn test_stdin_redirect_file() {
assert!(buf_stderr.is_empty());
}
#[test]
#[cfg(not(target_os = "windows"))]
#[cfg(feature = "chmod")]
fn test_permission_denied() {
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
at.touch("unreadable");
ts.ccmd("chmod").arg("0").arg("unreadable").succeeds();
ts.ucmd()
.set_stdin(Stdio::null())
.arg("unreadable")
.fails()
.stderr_is("tail: cannot open 'unreadable' for reading: Permission denied\n")
.no_stdout()
.code_is(1);
}
#[test]
#[cfg(not(target_os = "windows"))]
#[cfg(feature = "chmod")]
fn test_permission_denied_multiple() {
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
at.touch("file1");
at.touch("file2");
at.touch("unreadable");
ts.ccmd("chmod").arg("0").arg("unreadable").succeeds();
ts.ucmd()
.set_stdin(Stdio::null())
.args(&["file1", "unreadable", "file2"])
.fails()
.stderr_is("tail: cannot open 'unreadable' for reading: Permission denied\n")
.stdout_is("==> file1 <==\n\n==> file2 <==\n")
.code_is(1);
}
#[test]
#[cfg(target_os = "linux")]
fn test_follow_redirect_stdin_name_retry() {