From 9b8f2a9ee2dda6f745ee1544052bb59e324698ef Mon Sep 17 00:00:00 2001 From: David Peter Date: Tue, 22 Feb 2022 11:54:00 +0100 Subject: [PATCH] Move Stdio extraction to enum --- src/benchmark/executor.rs | 7 ++----- src/options.rs | 11 ++++++++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/benchmark/executor.rs b/src/benchmark/executor.rs index 44eada9..77dc1d7 100644 --- a/src/benchmark/executor.rs +++ b/src/benchmark/executor.rs @@ -1,7 +1,7 @@ use std::process::{ExitStatus, Stdio}; use crate::command::Command; -use crate::options::{CmdFailureAction, CommandOutputPolicy, Options, OutputStyleOption, Shell}; +use crate::options::{CmdFailureAction, Options, OutputStyleOption, Shell}; use crate::output::progress_bar::get_progress_bar; use crate::timer::{execute_and_measure, wall_clock_timer::WallClockTimer}; use crate::util::randomized_environment_offset; @@ -63,10 +63,7 @@ impl<'a> Executor for ShellExecutor<'a> { command: &Command<'_>, command_failure_action: Option, ) -> Result<(TimingResult, ExitStatus)> { - let (stdout, stderr) = match self.options.command_output_policy { - CommandOutputPolicy::Discard => (Stdio::null(), Stdio::null()), - CommandOutputPolicy::Forward => (Stdio::inherit(), Stdio::inherit()), - }; + let (stdout, stderr) = self.options.command_output_policy.get_stdout_stderr(); let mut command_builder = self.shell.command(); command_builder diff --git a/src/options.rs b/src/options.rs index 5aa84ef..1d4c3f7 100644 --- a/src/options.rs +++ b/src/options.rs @@ -1,4 +1,4 @@ -use std::process::Command; +use std::process::{Command, Stdio}; use std::{cmp, fmt}; use anyhow::ensure; @@ -124,6 +124,15 @@ impl Default for CommandOutputPolicy { } } +impl CommandOutputPolicy { + pub fn get_stdout_stderr(&self) -> (Stdio, Stdio) { + match self { + CommandOutputPolicy::Discard => (Stdio::null(), Stdio::null()), + CommandOutputPolicy::Forward => (Stdio::inherit(), Stdio::inherit()), + } + } +} + pub enum ExecutorKind { Shell(Shell), Mock(Option),