mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
sleep: Use fundu error types to improve error messages
This commit is contained in:
parent
3a28b616d9
commit
5fb091a4fb
2 changed files with 30 additions and 12 deletions
|
@ -10,11 +10,11 @@ fn test_invalid_time_interval() {
|
|||
new_ucmd!()
|
||||
.arg("xyz")
|
||||
.fails()
|
||||
.usage_error("invalid time interval 'xyz'");
|
||||
.usage_error("invalid time interval 'xyz': Invalid character: 'x' at position 1");
|
||||
new_ucmd!()
|
||||
.args(&["--", "-1"])
|
||||
.fails()
|
||||
.usage_error("invalid time interval '-1'");
|
||||
.usage_error("invalid time interval '-1': Number was negative");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -204,14 +204,16 @@ fn test_sleep_when_input_has_only_whitespace_then_error(#[case] input: &str) {
|
|||
.arg(input)
|
||||
.timeout(Duration::from_secs(10))
|
||||
.fails()
|
||||
.usage_error(format!("invalid time interval '{input}'"));
|
||||
.usage_error(format!(
|
||||
"invalid time interval '{input}': Found only whitespace in input"
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sleep_when_multiple_input_some_with_error_then_shows_all_errors() {
|
||||
let expected = "invalid time interval 'abc'\n\
|
||||
sleep: invalid time interval '1years'\n\
|
||||
sleep: invalid time interval ' '";
|
||||
let expected = "invalid time interval 'abc': Invalid character: 'a' at position 1\n\
|
||||
sleep: invalid time interval '1years': Invalid time unit: 'years' at position 2\n\
|
||||
sleep: invalid time interval ' ': Found only whitespace in input";
|
||||
|
||||
// Even if one of the arguments is valid, but the rest isn't, we should still fail and exit early.
|
||||
// So, the timeout of 10 seconds ensures we haven't executed `thread::sleep` with the only valid
|
||||
|
@ -228,5 +230,5 @@ fn test_negative_interval() {
|
|||
new_ucmd!()
|
||||
.args(&["--", "-1"])
|
||||
.fails()
|
||||
.usage_error("invalid time interval '-1'");
|
||||
.usage_error("invalid time interval '-1': Number was negative");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue