mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
shuf: fix error message text on negative-sized ranges
Found by @cakebaker: https://github.com/uutils/coreutils/pull/6011#discussion_r1501838317
This commit is contained in:
parent
4ee3f68e6a
commit
b233569b9c
2 changed files with 11 additions and 3 deletions
|
@ -471,10 +471,14 @@ fn parse_range(input_range: &str) -> Result<RangeInclusive<usize>, String> {
|
|||
let end = to
|
||||
.parse::<usize>()
|
||||
.map_err(|_| format!("invalid input range: {}", to.quote()))?;
|
||||
if begin <= end || begin == end + 1 {
|
||||
Ok(begin..=end)
|
||||
} else {
|
||||
Err(format!("invalid input range: {}", input_range.quote()))
|
||||
}
|
||||
} else {
|
||||
Err(format!("invalid input range: {}", input_range.quote()))
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_head_count(headcounts: Vec<String>) -> Result<usize, String> {
|
||||
|
|
|
@ -762,7 +762,11 @@ fn test_range_empty() {
|
|||
|
||||
#[test]
|
||||
fn test_range_empty_minus_one() {
|
||||
new_ucmd!().arg("-i5-3").succeeds().no_output();
|
||||
new_ucmd!()
|
||||
.arg("-i5-3")
|
||||
.fails()
|
||||
.no_stdout()
|
||||
.stderr_only("shuf: invalid input range: '5-3'\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -792,5 +796,5 @@ fn test_range_repeat_empty_minus_one() {
|
|||
.arg("-ri5-3")
|
||||
.fails()
|
||||
.no_stdout()
|
||||
.stderr_only("shuf: no lines to repeat\n");
|
||||
.stderr_only("shuf: invalid input range: '5-3'\n");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue