1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-30 20:47:46 +00:00

sort: improve handling of buffer size cmd arg

Instead of overflowing when calculating the buffer size, use
saturating_{pow, mul}.

When failing to parse the buffer size, we now crash instead of silently
ignoring the error.
This commit is contained in:
Michael Debertol 2021-05-22 14:00:07 +02:00
parent e7da8058dc
commit 088443276a
2 changed files with 46 additions and 32 deletions

View file

@ -17,7 +17,9 @@ fn test_helper(file_name: &str, args: &str) {
#[test]
fn test_buffer_sizes() {
let buffer_sizes = ["0", "50K", "1M", "1000G"];
let buffer_sizes = [
"0", "50K", "50k", "1M", "100M", "1000G", "10T", "500E", "1Y",
];
for buffer_size in &buffer_sizes {
new_ucmd!()
.arg("-n")
@ -30,14 +32,18 @@ fn test_buffer_sizes() {
}
#[test]
fn test_smaller_than_specified_segment() {
new_ucmd!()
.arg("-n")
.arg("-S")
.arg("100M")
.arg("ext_sort.txt")
.succeeds()
.stdout_is_fixture("ext_sort.expected");
fn test_invalid_buffer_size() {
let buffer_sizes = ["asd", "100f"];
for invalid_buffer_size in &buffer_sizes {
new_ucmd!()
.arg("-S")
.arg(invalid_buffer_size)
.fails()
.stderr_only(format!(
"sort: error: failed to parse buffer size `{}`: invalid digit found in string",
invalid_buffer_size
));
}
}
#[test]