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
Provenance
- Commit
365ff25- Tree
2a5dd7f- Author
David Peter <mail@david-peter.de>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
d9418e0
5 files changed+37 added−24 removed
modified:src/cli.rs+18 added-4 removed
20 unmodified lines21 .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 lines182 .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 linesmodified:src/options.rs+11 added-7 removed
280 unmodified lines281 }282 OutputStyleOption::Disabled => {}283 };284 285+ 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 };297 298 if matches.is_present("ignore-failure") {299 options.command_failure_action = CmdFailureAction::Ignore;68 unmodified linesmodified:tests/common.rs-6 removed
9 unmodified lines10 11 pub fn hyperfine() -> assert_cmd::Command {12 assert_cmd::Command::from_std(hyperfine_raw_command())13 }14-15-pub 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 line2 3 use tempfile::{tempdir, TempDir};4 5 mod common;6-use common::hyperfine_shell;6+use common::hyperfine;7 8 struct ExecutionOrderTest {9 cmd: assert_cmd::Command,10 expected_content: String,7 unmodified lines18 let tempdir = tempdir().unwrap();19 let logfile_path = tempdir.path().join("output.log");20 21 ExecutionOrderTest {22- cmd: hyperfine_shell(),22+ cmd: hyperfine(),23 expected_content: String::new(),24 logfile_path,25 tempdir,26 }252 unmodified linesmodified:tests/integration_tests.rs+6 added-5 removed
1 mod common;2-use common::{hyperfine, hyperfine_shell};2+use common::hyperfine;3 4 use predicates::prelude::*;5 6 pub fn hyperfine_debug() -> assert_cmd::Command {78 unmodified lines85 .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 }92 93 #[test]94-fn fails_for_unknown_shell_command() {95- hyperfine_shell()94+fn 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 }105 106 #[test]189 unmodified lines