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

split: more test coverage

This commit is contained in:
zhitkoff 2023-09-06 19:49:26 -04:00
parent e40e887022
commit 3be284e0d9
2 changed files with 34 additions and 1 deletions

View file

@ -1295,7 +1295,7 @@ where
// 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 {
if num_chunks == 0 || num_bytes == 0 {
return Ok(());
}

View file

@ -340,6 +340,18 @@ fn test_split_lines_number() {
.succeeds()
.no_stderr()
.no_stdout();
scene
.ucmd()
.args(&["--lines", "0", "file"])
.fails()
.code_is(1)
.stderr_only("split: invalid number of lines: 0\n");
scene
.ucmd()
.args(&["-0", "file"])
.fails()
.code_is(1)
.stderr_only("split: invalid number of lines: 0\n");
scene
.ucmd()
.args(&["--lines", "2fb", "file"])
@ -669,6 +681,15 @@ fn test_split_stdin_num_chunks() {
.stderr_only("split: -: cannot determine file size\n");
}
#[test]
fn test_split_stdin_num_kth_chunk() {
new_ucmd!()
.args(&["--number=1/2"])
.fails()
.code_is(1)
.stderr_only("split: -: cannot determine file size\n");
}
fn file_read(at: &AtPath, filename: &str) -> String {
let mut s = String::new();
at.open(filename).read_to_string(&mut s).unwrap();
@ -784,6 +805,10 @@ fn test_number_n() {
assert_eq!(file_read("xac"), "klmno");
assert_eq!(file_read("xad"), "pqrst");
assert_eq!(file_read("xae"), "uvwxyz\n");
new_ucmd!()
.args(&["--number=100", "/dev/null"])
.succeeds()
.stdout_only("");
}
#[test]
@ -792,10 +817,18 @@ fn test_number_kth_of_n() {
.args(&["--number=3/5", "asciilowercase.txt"])
.succeeds()
.stdout_only("klmno");
new_ucmd!()
.args(&["--number=5/5", "asciilowercase.txt"])
.succeeds()
.stdout_only("uvwxyz\n");
new_ucmd!()
.args(&["-e", "--number=99/100", "asciilowercase.txt"])
.succeeds()
.stdout_only("");
new_ucmd!()
.args(&["--number=3/10", "/dev/null"])
.succeeds()
.stdout_only("");
#[cfg(target_pointer_width = "64")]
new_ucmd!()
.args(&[