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

tee: correctly handle writing to read-only files

This commit is contained in:
Ben Wiederhake 2024-03-31 16:56:48 +02:00
parent 5c36ed92b8
commit 8ab825c49f
2 changed files with 38 additions and 11 deletions

View file

@ -3,6 +3,7 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use regex::Regex;
#[cfg(target_os = "linux")]
use std::fmt::Write;
@ -92,6 +93,27 @@ fn test_tee_no_more_writeable_1() {
assert_eq!(at.read(file_out), content);
}
#[test]
fn test_readonly() {
let (at, mut ucmd) = at_and_ucmd!();
let content_tee = "hello";
let content_file = "world";
let file_out = "tee_file_out";
let writable_file = "tee_file_out2";
at.write(file_out, content_file);
at.set_readonly(file_out);
ucmd.arg(file_out)
.arg(writable_file)
.pipe_in(content_tee)
.ignore_stdin_write_error()
.fails()
.stdout_is(content_tee)
// Windows says "Access is denied" for some reason.
.stderr_matches(&Regex::new("(Permission|Access is) denied").unwrap());
assert_eq!(at.read(file_out), content_file);
assert_eq!(at.read(writable_file), content_tee);
}
#[test]
#[cfg(target_os = "linux")]
fn test_tee_no_more_writeable_2() {