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

test(cat): add test for output appending to input file

This commit is contained in:
Dorian Péron 2025-02-05 00:53:45 +01:00 committed by Jeffrey Finkelstein
parent c9312eba9a
commit 9a88526867

View file

@ -9,6 +9,8 @@ use crate::common::util::vec_of_size;
use crate::common::util::TestScenario; use crate::common::util::TestScenario;
#[cfg(any(target_os = "linux", target_os = "android"))] #[cfg(any(target_os = "linux", target_os = "android"))]
use rlimit::Resource; use rlimit::Resource;
#[cfg(target_os = "linux")]
use std::fs::File;
use std::fs::OpenOptions; use std::fs::OpenOptions;
#[cfg(not(windows))] #[cfg(not(windows))]
use std::process::Stdio; use std::process::Stdio;
@ -646,3 +648,23 @@ fn test_u_ignored() {
.stdout_only("hello"); .stdout_only("hello");
} }
} }
#[test]
#[cfg(target_os = "linux")]
fn test_appending_same_input_output() {
let (at, mut ucmd) = at_and_ucmd!();
at.write("foo", "content");
let foo_file = at.plus_as_string("foo");
let file_read = File::open(&foo_file).unwrap();
let file_write = OpenOptions::new().append(true).open(&foo_file).unwrap();
ucmd.set_stdin(file_read);
ucmd.set_stdout(file_write);
ucmd.run()
.failure()
.no_stdout()
.stderr_contains("input file is output file");
}