1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

tests: Simplify logic of UCommand::run.

This commit is contained in:
Valentin Lorentz 2016-04-02 16:23:26 +02:00
parent b3b8a1ea54
commit fe5bc47971

View file

@ -486,8 +486,6 @@ impl UCommand {
} }
self.has_run = true; self.has_run = true;
log_info("run", &self.comm_string); log_info("run", &self.comm_string);
let prog = match self.stdin {
Some(ref input) => {
let mut result = self.raw let mut result = self.raw
.stdin(Stdio::piped()) .stdin(Stdio::piped())
.stdout(Stdio::piped()) .stdout(Stdio::piped())
@ -495,6 +493,7 @@ impl UCommand {
.spawn() .spawn()
.unwrap(); .unwrap();
if let Some(ref input) = self.stdin {
result.stdin result.stdin
.take() .take()
.unwrap_or_else( .unwrap_or_else(
@ -502,13 +501,10 @@ impl UCommand {
"Could not take child process stdin")) "Could not take child process stdin"))
.write_all(&input) .write_all(&input)
.unwrap_or_else(|e| panic!("{}", e)); .unwrap_or_else(|e| panic!("{}", e));
}
let prog = result.wait_with_output().unwrap();
result.wait_with_output().unwrap()
}
None => {
self.raw.output().unwrap()
}
};
CmdResult { CmdResult {
success: prog.status.success(), success: prog.status.success(),
stdout: from_utf8(&prog.stdout).unwrap().to_string(), stdout: from_utf8(&prog.stdout).unwrap().to_string(),