From fe5bc47971bf43e25b46d3ea179778a587e9d5f0 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sat, 2 Apr 2016 16:23:26 +0200 Subject: [PATCH] tests: Simplify logic of UCommand::run. --- tests/common/util.rs | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/tests/common/util.rs b/tests/common/util.rs index 84459153c..9448c8b70 100755 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -486,29 +486,25 @@ impl UCommand { } self.has_run = true; log_info("run", &self.comm_string); - let prog = match self.stdin { - Some(ref input) => { - let mut result = self.raw - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .unwrap(); + let mut result = self.raw + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .unwrap(); - result.stdin - .take() - .unwrap_or_else( - || panic!( - "Could not take child process stdin")) - .write_all(&input) - .unwrap_or_else(|e| panic!("{}", e)); + if let Some(ref input) = self.stdin { + result.stdin + .take() + .unwrap_or_else( + || panic!( + "Could not take child process stdin")) + .write_all(&input) + .unwrap_or_else(|e| panic!("{}", e)); + } + + let prog = result.wait_with_output().unwrap(); - result.wait_with_output().unwrap() - } - None => { - self.raw.output().unwrap() - } - }; CmdResult { success: prog.status.success(), stdout: from_utf8(&prog.stdout).unwrap().to_string(),