Skip to content

Commit 704421b

Browse files
authored
Merge pull request #7200 from cakebaker/timeout_add_f_and_p
timeout: add support for `-f` and `-p` short options
2 parents 5129aba + 55a4285 commit 704421b

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

src/uu/timeout/src/timeout.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ pub fn uu_app() -> Command {
129129
.arg(
130130
Arg::new(options::FOREGROUND)
131131
.long(options::FOREGROUND)
132+
.short('f')
132133
.help(
133134
"when not running timeout directly from a shell prompt, allow \
134135
COMMAND to read from the TTY and get TTY signals; in this mode, \
@@ -148,6 +149,7 @@ pub fn uu_app() -> Command {
148149
.arg(
149150
Arg::new(options::PRESERVE_STATUS)
150151
.long(options::PRESERVE_STATUS)
152+
.short('p')
151153
.help("exit with the same status as COMMAND, even when the command times out")
152154
.action(ArgAction::SetTrue),
153155
)

tests/by-util/test_timeout.rs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,11 @@ fn test_zero_timeout() {
6565
new_ucmd!()
6666
.args(&["-v", "0", "sleep", ".1"])
6767
.succeeds()
68-
.no_stderr()
69-
.no_stdout();
68+
.no_output();
7069
new_ucmd!()
7170
.args(&["-v", "0", "-s0", "-k0", "sleep", ".1"])
7271
.succeeds()
73-
.no_stderr()
74-
.no_stdout();
72+
.no_output();
7573
}
7674

7775
#[test]
@@ -82,15 +80,27 @@ fn test_command_empty_args() {
8280
.stderr_contains("timeout: empty string");
8381
}
8482

83+
#[test]
84+
fn test_foreground() {
85+
for arg in ["-f", "--foreground"] {
86+
new_ucmd!()
87+
.args(&[arg, ".1", "sleep", "10"])
88+
.fails()
89+
.code_is(124)
90+
.no_output();
91+
}
92+
}
93+
8594
#[test]
8695
fn test_preserve_status() {
87-
new_ucmd!()
88-
.args(&["--preserve-status", ".1", "sleep", "10"])
89-
.fails()
90-
// 128 + SIGTERM = 128 + 15
91-
.code_is(128 + 15)
92-
.no_stderr()
93-
.no_stdout();
96+
for arg in ["-p", "--preserve-status"] {
97+
new_ucmd!()
98+
.args(&[arg, ".1", "sleep", "10"])
99+
.fails()
100+
// 128 + SIGTERM = 128 + 15
101+
.code_is(128 + 15)
102+
.no_output();
103+
}
94104
}
95105

96106
#[test]
@@ -102,8 +112,7 @@ fn test_preserve_status_even_when_send_signal() {
102112
.args(&["-s", cont_spelling, "--preserve-status", ".1", "sleep", "2"])
103113
.succeeds()
104114
.code_is(0)
105-
.no_stderr()
106-
.no_stdout();
115+
.no_output();
107116
}
108117
}
109118

@@ -113,14 +122,12 @@ fn test_dont_overflow() {
113122
.args(&["9223372036854775808d", "sleep", "0"])
114123
.succeeds()
115124
.code_is(0)
116-
.no_stderr()
117-
.no_stdout();
125+
.no_output();
118126
new_ucmd!()
119127
.args(&["-k", "9223372036854775808d", "10", "sleep", "0"])
120128
.succeeds()
121129
.code_is(0)
122-
.no_stderr()
123-
.no_stdout();
130+
.no_output();
124131
}
125132

126133
#[test]
@@ -153,8 +160,7 @@ fn test_kill_after_long() {
153160
new_ucmd!()
154161
.args(&["--kill-after=1", "1", "sleep", "0"])
155162
.succeeds()
156-
.no_stdout()
157-
.no_stderr();
163+
.no_output();
158164
}
159165

160166
#[test]

0 commit comments

Comments
 (0)