]> git.lizzy.rs Git - rust.git/blob - library/test/src/helpers/exit_code.rs
Rollup merge of #89579 - workingjubilee:regression-test-80108, r=Mark-Simulacrum
[rust.git] / library / test / src / helpers / exit_code.rs
1 //! Helper module to detect subprocess exit code.
2
3 use std::process::ExitStatus;
4
5 #[cfg(not(unix))]
6 pub fn get_exit_code(status: ExitStatus) -> Result<i32, String> {
7     status.code().ok_or_else(|| "received no exit code from child process".into())
8 }
9
10 #[cfg(unix)]
11 pub 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 }