mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
sleep: Fix whitespace issues. Don't panic when adding durations.
Refactor error propagation and use show_error! instead of USimpleError.
This commit is contained in:
parent
68f75af678
commit
71bbebdc76
2 changed files with 55 additions and 10 deletions
|
@ -1,3 +1,5 @@
|
|||
use rstest::rstest;
|
||||
|
||||
// spell-checker:ignore dont
|
||||
use crate::common::util::*;
|
||||
|
||||
|
@ -180,6 +182,47 @@ fn test_sleep_when_multiple_inputs_exceed_max_duration_then_no_error() {
|
|||
.no_output();
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
#[case::whitespace_prefix(" 0.1s")]
|
||||
#[case::multiple_whitespace_prefix(" 0.1s")]
|
||||
#[case::whitespace_suffix("0.1s ")]
|
||||
#[case::mixed_newlines_spaces_tabs("\n\t0.1s \n ")]
|
||||
fn test_sleep_when_input_has_whitespace_then_no_error(#[case] input: &str) {
|
||||
new_ucmd!()
|
||||
.arg(input)
|
||||
.timeout(Duration::from_secs(10))
|
||||
.succeeds()
|
||||
.no_output();
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
#[case::only_space(" ")]
|
||||
#[case::only_tab("\t")]
|
||||
#[case::only_newline("\n")]
|
||||
fn test_sleep_when_input_has_only_whitespace_then_error(#[case] input: &str) {
|
||||
new_ucmd!()
|
||||
.arg(input)
|
||||
.timeout(Duration::from_secs(10))
|
||||
.fails()
|
||||
.usage_error(format!("invalid time interval '{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 ' '";
|
||||
|
||||
// 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
|
||||
// interval of `100000.0` seconds.
|
||||
new_ucmd!()
|
||||
.args(&["abc", "100000.0", "1years", " "])
|
||||
.timeout(Duration::from_secs(10))
|
||||
.fails()
|
||||
.usage_error(expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_negative_interval() {
|
||||
new_ucmd!()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue