evobench_tools/utillib/
exit_status_ext.rs

1pub trait ExitStatusExt {
2    fn status_and_outputs(&self) -> (std::process::ExitStatus, String);
3}
4
5impl ExitStatusExt for std::process::Output {
6    fn status_and_outputs(&self) -> (std::process::ExitStatus, String) {
7        let stdout = String::from_utf8_lossy(&self.stdout);
8        let stderr = String::from_utf8_lossy(&self.stderr);
9        let mut outputs = Vec::new();
10        if !stdout.is_empty() {
11            let need_newline = !stdout.ends_with("\n");
12            outputs.push(stdout);
13            if need_newline {
14                outputs.push("\n".into())
15            }
16        }
17        if !stderr.is_empty() {
18            let need_newline = !stderr.ends_with("\n");
19            outputs.push(stderr);
20            if need_newline {
21                outputs.push("\n".into())
22            }
23        }
24        (self.status, outputs.join(""))
25    }
26}