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

dd: misc gnu test (#6084)

* dd: check file is a dir for iflag directory

* Improve english

Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>

* dd: stderr output checking for "iflag directory" testcase

* dd: replace #[cfg(unix)] with #[test]

---------

Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
This commit is contained in:
sreehari prasad 2024-03-20 11:25:54 +05:30 committed by GitHub
parent 08172c28c0
commit 660014e532
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 0 deletions

View file

@ -310,6 +310,15 @@ impl<'a> Input<'a> {
}; };
#[cfg(unix)] #[cfg(unix)]
let mut src = Source::stdin_as_file(); let mut src = Source::stdin_as_file();
#[cfg(unix)]
if let Source::StdinFile(f) = &src {
// GNU compatibility:
// this will check whether stdin points to a folder or not
if f.metadata()?.is_file() && settings.iflags.directory {
show_error!("standard input: not a directory");
return Err(1.into());
}
};
if settings.skip > 0 { if settings.skip > 0 {
src.skip(settings.skip)?; src.skip(settings.skip)?;
} }

View file

@ -1715,6 +1715,20 @@ fn test_reading_partial_blocks_from_fifo_unbuffered() {
assert!(output.stderr.starts_with(expected)); assert!(output.stderr.starts_with(expected));
} }
#[test]
#[cfg(any(target_os = "linux", target_os = "android"))]
fn test_iflag_directory_fails_when_file_is_passed_via_std_in() {
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
at.make_file("input");
let filename = at.plus_as_string("input");
new_ucmd!()
.args(&["iflag=directory", "count=0"])
.set_stdin(std::process::Stdio::from(File::open(filename).unwrap()))
.fails()
.stderr_contains("standard input: not a directory");
}
#[test] #[test]
fn test_stdin_stdout_not_rewound_even_when_connected_to_seekable_file() { fn test_stdin_stdout_not_rewound_even_when_connected_to_seekable_file() {
use std::process::Stdio; use std::process::Stdio;