]> git.proxmox.com Git - rustc.git/blame - vendor/tester/src/helpers/exit_code.rs
Update upstream source from tag 'upstream/1.52.1+dfsg1'
[rustc.git] / vendor / tester / src / helpers / exit_code.rs
CommitLineData
f20569fa
XL
1//! Helper module to detect subprocess exit code.
2
3use std::process::ExitStatus;
4
5#[cfg(not(unix))]
6pub fn get_exit_code(status: ExitStatus) -> Result<i32, String> {
7 status.code().ok_or("received no exit code from child process".into())
8}
9
10#[cfg(unix)]
11pub fn get_exit_code(status: ExitStatus) -> Result<i32, String> {
12 use std::os::unix::process::ExitStatusExt;
13 match status.code() {
14 Some(code) => Ok(code),
15 None => match status.signal() {
16 Some(signal) => Err(format!("child process exited with signal {}", signal)),
17 None => Err("child process exited with unknown signal".into()),
18 },
19 }
20}