blob: 8e20bf7cc2062e964684ce8a8788b0908a1cd670 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
use std::process;
pub trait CommandExt {
fn quiet(&mut self) -> &mut Self;
fn expect_success_status(&mut self, msg: &str) -> process::ExitStatus;
fn expect_success_output(&mut self, msg: &str) -> process::Output;
}
impl CommandExt for process::Command {
fn quiet(&mut self) -> &mut Self {
self.stdout(process::Stdio::null())
.stderr(process::Stdio::null())
}
fn expect_success_status(&mut self, msg: &str) -> process::ExitStatus {
self.expect_success_output(msg).status
}
fn expect_success_output(&mut self, msg: &str) -> process::Output {
let output = self.output().expect(msg);
if !output.status.success() {
panic!(
"{}: command {:?} exited with error {:?}\nSTDOUT: {}\nSTDERR: {}",
msg,
self,
output.status.code(),
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr)
);
}
output
}
}
|