1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

Merge pull request #3284 from jfinkels/sleep-usage-error

sleep: give usage error on invalid time interval
This commit is contained in:
Sylvestre Ledru 2022-03-21 09:27:47 +01:00 committed by GitHub
commit 0bc9a05846
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View file

@ -9,7 +9,7 @@ use std::thread;
use std::time::Duration;
use uucore::{
error::{UResult, USimpleError},
error::{UResult, UUsageError},
format_usage,
};
@ -64,7 +64,7 @@ fn sleep(args: &[&str]) -> UResult<()> {
Duration::new(0, 0),
|result, arg| match uucore::parse_time::from_str(&arg[..]) {
Ok(m) => Ok(m.saturating_add(result)),
Err(f) => Err(USimpleError::new(1, f)),
Err(f) => Err(UUsageError::new(1, f)),
},
)?;
thread::sleep(sleep_dur);

View file

@ -3,6 +3,14 @@ use crate::common::util::*;
use std::time::{Duration, Instant};
#[test]
fn test_invalid_time_interval() {
new_ucmd!()
.arg("xyz")
.fails()
.usage_error("invalid time interval 'xyz'");
}
#[test]
fn test_sleep_no_suffix() {
let millis_100 = Duration::from_millis(100);