use crate::os::unix::process::{CommandExt, ExitStatusExt};
use crate::panic::catch_unwind;
use crate::process::Command;
#[test]
fn exitstatus_display_tests() {
use crate::os::unix::process::ExitStatusExt;
use crate::process::ExitStatus;
let t = |v, s| assert_eq!(s, format!("{}", <ExitStatus as ExitStatusExt>::from_raw(v)));
t(0x0000f, "signal: 15 (SIGTERM)");
t(0x0008b, "signal: 11 (SIGSEGV) (core dumped)");
t(0x00000, "exit status: 0");
t(0x0ff00, "exit status: 255");
if cfg!(target_os = "linux") {
t(0x0137f, "stopped (not terminated) by signal: 19 (SIGSTOP)");
t(0x0ffff, "continued (WIFCONTINUED)");
}
if cfg!(all(target_os = "linux", target_env = "gnu")) {
t(0x000ff, "unrecognised wait status: 255 0xff");
}
}
#[test]
#[cfg_attr(target_os = "emscripten", ignore)]
fn test_command_fork_no_unwind() {
let got = catch_unwind(|| {
let mut c = Command::new("echo");
c.arg("hi");
unsafe {
c.pre_exec(|| panic!("{}", "crash now!"));
}
let st = c.status().expect("failed to get command status");
dbg!(st);
st
});
dbg!(&got);
let status = got.expect("panic unexpectedly propagated");
dbg!(status);
let signal = status.signal().expect("expected child process to die of signal");
assert!(
signal == libc::SIGABRT
|| signal == libc::SIGILL
|| signal == libc::SIGTRAP
|| signal == libc::SIGSEGV
);
}