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

timeout: produce usage error on invalid signal

Produce a usage error on an invalid signal argument. For example,

    $ timeout --signal=invalid 1 sleep 0
    timeout: 'invalid': invalid signal
    Try 'timeout --help' for more information.
This commit is contained in:
Jeffrey Finkelstein 2022-03-22 21:02:13 -04:00 committed by Sylvestre Ledru
parent 1cd72a621a
commit 760a15aa74
2 changed files with 12 additions and 1 deletions

View file

@ -57,7 +57,10 @@ impl Config {
let signal_result = signal_by_name_or_value(signal_); let signal_result = signal_by_name_or_value(signal_);
match signal_result { match signal_result {
None => { None => {
unreachable!("invalid signal {}", signal_.quote()); return Err(UUsageError::new(
ExitStatus::TimeoutFailed.into(),
format!("{}: invalid signal", signal_.quote()),
))
} }
Some(signal_value) => signal_value, Some(signal_value) => signal_value,
} }

View file

@ -97,3 +97,11 @@ fn test_negative_interval() {
.fails() .fails()
.usage_error("invalid time interval '-1'"); .usage_error("invalid time interval '-1'");
} }
#[test]
fn test_invalid_signal() {
new_ucmd!()
.args(&["-s", "invalid", "1", "sleep", "0"])
.fails()
.usage_error("'invalid': invalid signal");
}