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

timeout: add support for -f and -p short options

This commit is contained in:
Daniel Hofstetter 2025-01-23 16:05:14 +01:00
parent 5b056704da
commit df91808649
2 changed files with 22 additions and 7 deletions

View file

@ -129,6 +129,7 @@ pub fn uu_app() -> Command {
.arg( .arg(
Arg::new(options::FOREGROUND) Arg::new(options::FOREGROUND)
.long(options::FOREGROUND) .long(options::FOREGROUND)
.short('f')
.help( .help(
"when not running timeout directly from a shell prompt, allow \ "when not running timeout directly from a shell prompt, allow \
COMMAND to read from the TTY and get TTY signals; in this mode, \ COMMAND to read from the TTY and get TTY signals; in this mode, \
@ -148,6 +149,7 @@ pub fn uu_app() -> Command {
.arg( .arg(
Arg::new(options::PRESERVE_STATUS) Arg::new(options::PRESERVE_STATUS)
.long(options::PRESERVE_STATUS) .long(options::PRESERVE_STATUS)
.short('p')
.help("exit with the same status as COMMAND, even when the command times out") .help("exit with the same status as COMMAND, even when the command times out")
.action(ArgAction::SetTrue), .action(ArgAction::SetTrue),
) )

View file

@ -82,15 +82,28 @@ fn test_command_empty_args() {
.stderr_contains("timeout: empty string"); .stderr_contains("timeout: empty string");
} }
#[test]
fn test_foreground() {
for arg in ["-f", "--foreground"] {
new_ucmd!()
.args(&[arg, ".1", "sleep", "10"])
.fails()
.code_is(124)
.no_output();
}
}
#[test] #[test]
fn test_preserve_status() { fn test_preserve_status() {
new_ucmd!() for arg in ["-p", "--preserve-status"] {
.args(&["--preserve-status", ".1", "sleep", "10"]) new_ucmd!()
.fails() .args(&[arg, ".1", "sleep", "10"])
// 128 + SIGTERM = 128 + 15 .fails()
.code_is(128 + 15) // 128 + SIGTERM = 128 + 15
.no_stderr() .code_is(128 + 15)
.no_stdout(); .no_stderr()
.no_stdout();
}
} }
#[test] #[test]