From dc8e27a4af2fe58a5fba605c393039f5d58ec88a Mon Sep 17 00:00:00 2001 From: Steve Nease Date: Sun, 11 Sep 2022 16:20:22 -0500 Subject: [PATCH 01/10] Added --stdin-data argument This argument accepts a path to a file. The data contained in the file will be passed to the command via stdin. Closes sharkdp/hyperfine#541 --- src/benchmark/executor.rs | 8 +++++-- src/cli.rs | 8 +++++++ src/error.rs | 2 ++ src/options.rs | 47 +++++++++++++++++++++++++++++++++++++- tests/example_stdin_data | 1 + tests/integration_tests.rs | 28 +++++++++++++++++++++++ 6 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 tests/example_stdin_data diff --git a/src/benchmark/executor.rs b/src/benchmark/executor.rs index a8f84a9c6..5bd754a52 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, CommandInputPolicy, CommandOutputPolicy, Options, OutputStyleOption, Shell}; use crate::output::progress_bar::get_progress_bar; use crate::timer::{execute_and_measure, TimerResult}; use crate::util::randomized_environment_offset; @@ -36,11 +36,13 @@ pub trait Executor { fn run_command_and_measure_common( mut command: std::process::Command, command_failure_action: CmdFailureAction, + command_input_policy: &CommandInputPolicy, command_output_policy: &CommandOutputPolicy, command_name: &str, ) -> Result { let (stdout, stderr) = command_output_policy.get_stdout_stderr()?; - command.stdin(Stdio::null()).stdout(stdout).stderr(stderr); + let stdin = command_input_policy.get_stdin()?; + command.stdin(stdin).stdout(stdout).stderr(stderr); command.env( "HYPERFINE_RANDOMIZED_ENVIRONMENT_OFFSET", @@ -83,6 +85,7 @@ impl<'a> Executor for RawExecutor<'a> { let result = run_command_and_measure_common( command.get_command()?, command_failure_action.unwrap_or(self.options.command_failure_action), + &self.options.command_input_policy, &self.options.command_output_policy, &command.get_command_line(), )?; @@ -136,6 +139,7 @@ impl<'a> Executor for ShellExecutor<'a> { let mut result = run_command_and_measure_common( command_builder, command_failure_action.unwrap_or(self.options.command_failure_action), + &self.options.command_input_policy, &self.options.command_output_policy, &command.get_command_line(), )?; diff --git a/src/cli.rs b/src/cli.rs index 75f8e238b..88fd2b7eb 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -311,6 +311,14 @@ fn build_command() -> Command<'static> { .hide(true) .help("Enable debug mode which does not actually run commands, but returns fake times when the command is 'sleep