tests: Make output capture optional

Only some tests require the output for the tests to be captured so
default to not capturing the output to a pipe and instead make it
controllable.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2020-02-27 11:56:10 +00:00
parent dae7608b1e
commit 559b70cf0a

View File

@ -716,6 +716,7 @@ mod tests {
struct GuestCommand<'a> { struct GuestCommand<'a> {
command: Command, command: Command,
guest: &'a Guest<'a>, guest: &'a Guest<'a>,
capture_output: bool,
} }
impl<'a> GuestCommand<'a> { impl<'a> GuestCommand<'a> {
@ -723,14 +724,24 @@ mod tests {
Self { Self {
command: Command::new("target/release/cloud-hypervisor"), command: Command::new("target/release/cloud-hypervisor"),
guest, guest,
capture_output: false,
} }
} }
fn capture_output(&mut self) -> &mut Self {
self.capture_output = true;
self
}
fn spawn(&mut self) -> io::Result<Child> { fn spawn(&mut self) -> io::Result<Child> {
self.command if self.capture_output {
.stderr(Stdio::piped()) self.command
.stdout(Stdio::piped()) .stderr(Stdio::piped())
.spawn() .stdout(Stdio::piped())
.spawn()
} else {
self.command.spawn()
}
} }
fn args<I, S>(&mut self, args: I) -> &mut Self fn args<I, S>(&mut self, args: I) -> &mut Self
@ -1991,6 +2002,7 @@ mod tests {
.default_net() .default_net()
.args(&["--serial", "null"]) .args(&["--serial", "null"])
.args(&["--console", "off"]) .args(&["--console", "off"])
.capture_output()
.spawn() .spawn()
.unwrap(); .unwrap();
@ -2038,6 +2050,7 @@ mod tests {
.default_net() .default_net()
.args(&["--serial", "tty"]) .args(&["--serial", "tty"])
.args(&["--console", "off"]) .args(&["--console", "off"])
.capture_output()
.spawn() .spawn()
.unwrap(); .unwrap();
@ -2137,6 +2150,7 @@ mod tests {
.default_disks() .default_disks()
.default_net() .default_net()
.args(&["--console", "tty"]) .args(&["--console", "tty"])
.capture_output()
.spawn() .spawn()
.unwrap(); .unwrap();