mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
sleep: give usage error on invalid time interval
For example,
$ sleep xyz
sleep: invalid time interval 'xyz'
Try 'sleep --help' for more information.
This matches the behavior of GNU sleep.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user