Make --shell=none the default (#982)

This commit is contained in:
David Peter authored and GitHub committed 2026-10-06 08:41:59 +02:00
1 parent ef86c830b5
commit ab86cb99cc
7 files changed
+93 -51

No files matched your search

+15 -8
View File
@@ -36,8 +36,8 @@ fn build_command() -> Command {
Arg::new("command")
.help("The command to benchmark. This can be the name of an executable, a command \
line like \"grep -i todo\" or a shell command like \"sleep 0.5 && echo test\". \
The latter is only available if the shell is not explicitly disabled via \
'--shell=none'. If multiple commands are given, hyperfine will show a \
The latter requires a shell, which can be enabled via '-S' or '--shell=...'. \
If multiple commands are given, hyperfine will show a \
comparison of the respective runtimes.")
.required(true)
.action(ArgAction::Append)
@@ -181,7 +181,7 @@ fn build_command() -> Command {
Example: hyperfine --prepare 'make clean' -P threads 1 8 'make -j {threads}'\n\n\
This performs benchmarks for 'make -j 1', 'make -j 2', …, 'make -j 8'.\n\n\
To have the value increase following different patterns, use shell arithmetic.\n\n \
Example: hyperfine -P size 0 3 'sleep $((2**{size}))'\n\n\
Example: hyperfine --shell=bash -P size 0 3 'sleep $((2**{size}))'\n\n\
This performs benchmarks with power of 2 increases: 'sleep 1', 'sleep 2', 'sleep 4', …\n\
The exact syntax may vary depending on your shell and OS."
),
@@ -220,18 +220,25 @@ fn build_command() -> Command {
.arg(
Arg::new("shell")
.long("shell")
.short('S')
.action(ArgAction::Set)
.value_name("SHELL")
.overrides_with("shell")
.value_hint(ValueHint::CommandString)
.help("Set the shell to use for executing benchmarked commands. This can be the \
.help("Set the shell to use for executing commands (default: none). This can be the \
name or the path to the shell executable, or a full command line \
like \"bash --norc\". It can also be set to \"default\" to explicitly select \
the default shell on this platform. Finally, this can also be set to \
the platform shell (sh on Unix, cmd.exe on Windows). It can also be set to \
\"none\" to disable the shell. In this case, commands will be executed \
directly. They can still have arguments, but more complex things like \
\"sleep 0.1; sleep 0.2\" are not possible without a shell.")
\"sleep 0.1; sleep 0.2\" are not possible without a shell. This option also \
applies to setup, prepare, conclude, and cleanup commands.")
)
.arg(
Arg::new("default-shell")
.short('S')
.action(ArgAction::SetTrue)
.conflicts_with_all(["shell", "no-shell", "debug-mode"])
.help("An alias for '--shell=default' (sh on Unix, cmd.exe on Windows).")
)
.arg(
Arg::new("no-shell")
@@ -383,7 +390,7 @@ fn build_command() -> Command {
This option can be specified once for all commands or multiple times, once for \
each command. Note: If you want to log the output of each and every iteration, \
you can use a shell redirection and the '$HYPERFINE_ITERATION' environment variable:\n \
hyperfine 'my-command > output-${HYPERFINE_ITERATION}.log'\n\n",
hyperfine -S 'my-command > output-${HYPERFINE_ITERATION}.log'\n\n",
),
)
.arg(
+15 -17
View File
@@ -29,12 +29,6 @@ pub enum Shell {
Custom(Vec<String>),
}
impl Default for Shell {
fn default() -> Self {
Shell::Default(DEFAULT_SHELL)
}
}
impl fmt::Display for Shell {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
@@ -45,6 +39,11 @@ impl fmt::Display for Shell {
}
impl Shell {
/// Select the platform shell (sh on Unix, cmd.exe on Windows).
pub fn platform_default() -> Self {
Shell::Default(DEFAULT_SHELL)
}
/// Parse given string as shell command line
pub fn parse_from_str<'a>(s: &str) -> Result<Self, OptionsError<'a>> {
let v = shell_words::split(s).map_err(OptionsError::ShellParseError)?;
@@ -181,19 +180,14 @@ impl CommandOutputPolicy {
}
}
#[derive(Debug, PartialEq)]
#[derive(Debug, Default, PartialEq)]
pub enum ExecutorKind {
#[default]
Raw,
Shell(Shell),
Mock(Option<String>),
}
impl Default for ExecutorKind {
fn default() -> Self {
ExecutorKind::Shell(Shell::default())
}
}
/// The main settings for a hyperfine benchmark session
pub struct Options {
/// Upper and lower bound for the number of benchmark runs
@@ -401,15 +395,19 @@ impl Options {
options.executor_kind = if matches.get_flag("no-shell") {
ExecutorKind::Raw
} else if matches.get_flag("default-shell") {
ExecutorKind::Shell(Shell::platform_default())
} else {
match (
matches.get_flag("debug-mode"),
matches.get_one::<String>("shell"),
) {
(false, Some(shell)) if shell == "default" => ExecutorKind::Shell(Shell::default()),
(false, Some(shell)) if shell == "default" => {
ExecutorKind::Shell(Shell::platform_default())
}
(false, Some(shell)) if shell == "none" => ExecutorKind::Raw,
(false, Some(shell)) => ExecutorKind::Shell(Shell::parse_from_str(shell)?),
(false, None) => ExecutorKind::Shell(Shell::default()),
(false, None) => ExecutorKind::default(),
(true, Some(shell)) => ExecutorKind::Mock(Some(shell.into())),
(true, None) => ExecutorKind::Mock(None),
}
@@ -532,8 +530,8 @@ impl Options {
}
#[test]
fn test_default_shell() {
let shell = Shell::default();
fn test_platform_default_shell() {
let shell = Shell::platform_default();
let s = format!("{shell}");
assert_eq!(&s, DEFAULT_SHELL);