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

Merge pull request #3274 from jfinkels/split-elide-empty-files

split: elide all chunks when input file is empty
This commit is contained in:
Sylvestre Ledru 2022-03-19 22:52:57 +01:00 committed by GitHub
commit 1d17400b80
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View file

@ -984,6 +984,13 @@ where
(num_chunks, chunk_size)
};
// If we would have written zero chunks of output, then terminate
// immediately. This happens on `split -e -n 3 /dev/null`, for
// example.
if num_chunks == 0 {
return Ok(());
}
let num_chunks: usize = num_chunks
.try_into()
.map_err(|_| USimpleError::new(1, "Number of chunks too big"))?;

View file

@ -571,6 +571,19 @@ fn test_elide_empty_files() {
assert!(!at.plus("xad").exists());
}
#[test]
#[cfg(unix)]
fn test_elide_dev_null() {
let (at, mut ucmd) = at_and_ucmd!();
ucmd.args(&["-e", "-n", "3", "/dev/null"])
.succeeds()
.no_stdout()
.no_stderr();
assert!(!at.plus("xaa").exists());
assert!(!at.plus("xab").exists());
assert!(!at.plus("xac").exists());
}
#[test]
fn test_lines() {
let (at, mut ucmd) = at_and_ucmd!();