From df91808649fbd44af676dbb23802d9f4834e614d Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Thu, 23 Jan 2025 16:05:14 +0100 Subject: [PATCH] timeout: add support for -f and -p short options --- src/uu/timeout/src/timeout.rs | 2 ++ tests/by-util/test_timeout.rs | 27 ++++++++++++++++++++------- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/uu/timeout/src/timeout.rs b/src/uu/timeout/src/timeout.rs index 2ba93769a..3194d2737 100644 --- a/src/uu/timeout/src/timeout.rs +++ b/src/uu/timeout/src/timeout.rs @@ -129,6 +129,7 @@ pub fn uu_app() -> Command { .arg( Arg::new(options::FOREGROUND) .long(options::FOREGROUND) + .short('f') .help( "when not running timeout directly from a shell prompt, allow \ COMMAND to read from the TTY and get TTY signals; in this mode, \ @@ -148,6 +149,7 @@ pub fn uu_app() -> Command { .arg( Arg::new(options::PRESERVE_STATUS) .long(options::PRESERVE_STATUS) + .short('p') .help("exit with the same status as COMMAND, even when the command times out") .action(ArgAction::SetTrue), ) diff --git a/tests/by-util/test_timeout.rs b/tests/by-util/test_timeout.rs index 1ba6445c8..a4bf0e67b 100644 --- a/tests/by-util/test_timeout.rs +++ b/tests/by-util/test_timeout.rs @@ -82,15 +82,28 @@ fn test_command_empty_args() { .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] fn test_preserve_status() { - new_ucmd!() - .args(&["--preserve-status", ".1", "sleep", "10"]) - .fails() - // 128 + SIGTERM = 128 + 15 - .code_is(128 + 15) - .no_stderr() - .no_stdout(); + for arg in ["-p", "--preserve-status"] { + new_ucmd!() + .args(&[arg, ".1", "sleep", "10"]) + .fails() + // 128 + SIGTERM = 128 + 15 + .code_is(128 + 15) + .no_stderr() + .no_stdout(); + } } #[test]