mirror of
https://github.com/uutils/coreutils
synced 2024-12-13 23:02:38 +00:00
1aa6fd1468
Fix a bug where `timeout --preserve-status` was not correctly preserving the status code of the child process if it timed out. When that happens, the status code of the child process is considered to be the signal number (in this case, `SIGTERM`). The exit status of `timeout` is then 128 plus the numeric code associated with `SIGTERM`.
66 lines
1.7 KiB
Rust
66 lines
1.7 KiB
Rust
use crate::common::util::*;
|
|
|
|
// FIXME: this depends on the system having true and false in PATH
|
|
// the best solution is probably to generate some test binaries that we can call for any
|
|
// utility that requires executing another program (kill, for instance)
|
|
#[test]
|
|
fn test_subcommand_return_code() {
|
|
new_ucmd!().arg("1").arg("true").succeeds();
|
|
|
|
new_ucmd!().arg("1").arg("false").run().status_code(1);
|
|
}
|
|
|
|
#[test]
|
|
fn test_command_with_args() {
|
|
new_ucmd!()
|
|
.args(&["1700", "echo", "-n", "abcd"])
|
|
.succeeds()
|
|
.stdout_only("abcd");
|
|
}
|
|
|
|
#[test]
|
|
fn test_verbose() {
|
|
for &verbose_flag in &["-v", "--verbose"] {
|
|
new_ucmd!()
|
|
.args(&[verbose_flag, ".1", "sleep", "10"])
|
|
.fails()
|
|
.stderr_only("timeout: sending signal TERM to command 'sleep'");
|
|
new_ucmd!()
|
|
.args(&[verbose_flag, "-s0", "-k.1", ".1", "sleep", "10"])
|
|
.fails()
|
|
.stderr_only("timeout: sending signal EXIT to command 'sleep'\ntimeout: sending signal KILL to command 'sleep'");
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn test_zero_timeout() {
|
|
new_ucmd!()
|
|
.args(&["-v", "0", "sleep", ".1"])
|
|
.succeeds()
|
|
.no_stderr()
|
|
.no_stdout();
|
|
new_ucmd!()
|
|
.args(&["-v", "0", "-s0", "-k0", "sleep", ".1"])
|
|
.succeeds()
|
|
.no_stderr()
|
|
.no_stdout();
|
|
}
|
|
|
|
#[test]
|
|
fn test_command_empty_args() {
|
|
new_ucmd!()
|
|
.args(&["", ""])
|
|
.fails()
|
|
.stderr_contains("timeout: empty string");
|
|
}
|
|
|
|
#[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();
|
|
}
|