1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 19:47:45 +00:00

split: use "parse_size" from uucore

* make stderr of parsing SIZE/NUMBER argument consistent with GNU's behavior
* add error handling
* add tests
This commit is contained in:
Jan Scheer 2021-06-02 18:37:21 +02:00
parent 6b8de1dd8b
commit 2f5f7c6fa1
3 changed files with 69 additions and 37 deletions

View file

@ -285,3 +285,49 @@ fn test_filter_command_fails() {
ucmd.args(&["--filter=/a/path/that/totally/does/not/exist", name])
.fails();
}
#[test]
fn test_split_lines_number() {
// Test if stdout/stderr for '--lines' option is correct
new_ucmd!()
.args(&["--lines", "2"])
.pipe_in("abcde")
.succeeds()
.no_stderr()
.no_stdout();
new_ucmd!()
.args(&["--lines", "2fb"])
.pipe_in("abcde")
.fails()
.code_is(1)
.stderr_only("split: invalid number of lines: 2fb");
}
#[test]
fn test_split_invalid_bytes_size() {
new_ucmd!()
.args(&["-b", "1024R"])
.fails()
.code_is(1)
.stderr_only("split: invalid number of bytes: 1024R");
#[cfg(not(target_pointer_width = "128"))]
new_ucmd!()
.args(&["-b", "1Y"])
.fails()
.code_is(1)
.stderr_only("split: invalid number of bytes: 1Y: Value too large for defined data type");
#[cfg(target_pointer_width = "32")]
{
let sizes = ["1000G", "10T"];
for size in &sizes {
new_ucmd!()
.args(&["-b", size])
.fails()
.code_is(1)
.stderr_only(format!(
"split: invalid number of bytes: {}: Value too large for defined data type",
size
));
}
}
}