Skip to content
Myr

Switch to --shell=none/-N, do not change the default

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Peter · committed by David Peter · parent d9418e0 · Browse files · 5 files+37 added−24 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+37 added−24 removed

  • tests:+8 added−13 removed
  • other:+29 added−11 removed

5 files+37 added−24 removed

modified:src/cli.rs+18 added-4 removed
20 unmodified lines
21 .max_term_width(90)22 .about("A command-line benchmarking tool.")23 .arg(24 Arg::new("command")25 .help("Command to benchmark. This can be the name of an executable or a shell \26 command like \"sleep 0.5 && echo test\". If multiple commands are given, \27 hyperfine will show a comparison of the respective runtimes.")25 .help("The command to benchmark. This can be the name of an executable, a command \26 line like \"grep -i todo\" or a shell command like \"sleep 0.5 && echo test\". \27 The latter is only available if the shell is not explicitly disabled via \28 '--shell=none'. If multiple commands are given, hyperfine will show a \29 comparison of the respective runtimes.")30 .required(true)31 .multiple_occurrences(true)32 .forbid_empty_values(true),33 )
148 unmodified lines
182 .short('S')183 .takes_value(true)184 .value_name("SHELL")185 .overrides_with("shell")184 .help("Set the shell to use for executing benchmarked commands."),186 .help("Set the shell to use for executing benchmarked commands. This can be the \187 name or the path to the shell executable, or a full command line \188 like \"bash --norc\". It can also be set to \"default\" to explicitly select \189 the default shell on this patform. Finally, this can also be set to \190 \"none\" to disable the shell. In this case, commands will be executed \191 directly. They can still have arguments, but more complex things like \192 \"sleep 0.1; sleep 0.2\" are not possible without a shell.")193 )194 .arg(195 Arg::new("no-shell")196 .short('N')197 .conflicts_with_all(&["shell", "debug-mode"])198 .help("An alias for '--shell=none'.")199 )200 .arg(201 Arg::new("ignore-failure")202 .long("ignore-failure")203 .short('i')204 .help("Ignore non-zero exit codes of the benchmarked programs."),
73 unmodified lines
modified:src/options.rs+11 added-7 removed
280 unmodified lines
281 }282 OutputStyleOption::Disabled => {}283 };284285 options.executor_kind = if matches.is_present("no-shell") {286 ExecutorKind::Raw287 } else {285 options.executor_kind = match (matches.is_present("debug-mode"), matches.value_of("shell"))286 {287 (false, Some(shell)) if shell == "default" => ExecutorKind::Shell(Shell::default()),288 (false, Some(shell)) => ExecutorKind::Shell(Shell::parse_from_str(shell)?),289 (false, None) => ExecutorKind::Raw,290 (true, Some(shell)) => ExecutorKind::Mock(Some(shell.into())),291 (true, None) => ExecutorKind::Mock(None),288 match (matches.is_present("debug-mode"), matches.value_of("shell")) {289 (false, Some(shell)) if shell == "default" => ExecutorKind::Shell(Shell::default()),290 (false, Some(shell)) if shell == "none" => ExecutorKind::Raw,291 (false, Some(shell)) => ExecutorKind::Shell(Shell::parse_from_str(shell)?),292 (false, None) => ExecutorKind::Shell(Shell::default()),293 (true, Some(shell)) => ExecutorKind::Mock(Some(shell.into())),294 (true, None) => ExecutorKind::Mock(None),295 }296 };297298 if matches.is_present("ignore-failure") {299 options.command_failure_action = CmdFailureAction::Ignore;
68 unmodified lines
modified:tests/common.rs-6 removed
9 unmodified lines
1011pub fn hyperfine() -> assert_cmd::Command {12 assert_cmd::Command::from_std(hyperfine_raw_command())13}1415pub fn hyperfine_shell() -> assert_cmd::Command {16 let mut cmd = hyperfine();17 cmd.arg("--shell=default");18 cmd19}
modified:tests/execution_order_tests.rs+2 added-2 removed
1 unmodified line
23use tempfile::{tempdir, TempDir};45mod common;6use common::hyperfine_shell;6use common::hyperfine;78struct ExecutionOrderTest {9 cmd: assert_cmd::Command,10 expected_content: String,
7 unmodified lines
18 let tempdir = tempdir().unwrap();19 let logfile_path = tempdir.path().join("output.log");2021 ExecutionOrderTest {22 cmd: hyperfine_shell(),22 cmd: hyperfine(),23 expected_content: String::new(),24 logfile_path,25 tempdir,26 }
252 unmodified lines
modified:tests/integration_tests.rs+6 added-5 removed
1mod common;2use common::{hyperfine, hyperfine_shell};2use common::hyperfine;34use predicates::prelude::*;56pub fn hyperfine_debug() -> assert_cmd::Command {
78 unmodified lines
85 .arg("some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577")86 .assert()87 .failure()88 .stderr(predicate::str::contains(89 "Failed to run command 'some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577'",89 "Command terminated with non-zero exit code",90 ));91}9293#[test]94fn fails_for_unknown_shell_command() {95 hyperfine_shell()94fn fails_for_unknown_command_without_shell() {95 hyperfine()96 .arg("--shell=none")97 .arg("--runs=1")98 .arg("some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577")99 .assert()100 .failure()101 .stderr(predicate::str::contains(101 "Command terminated with non-zero exit code",102 "Failed to run command 'some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577'",103 ));104}105106#[test]
189 unmodified lines