mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-03 09:23:00 +00:00
Switch to --shell=none/-N, do not change the default
This commit is contained in:
1 parent
d9418e0731
commit
365ff2584d
5 files changed
+37
-24
No files matched your search
+18
-4
@@ -22,9 +22,11 @@ fn build_command() -> Command<'static> {
|
|||||||
.about("A command-line benchmarking tool.")
|
.about("A command-line benchmarking tool.")
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("command")
|
Arg::new("command")
|
||||||
.help("Command to benchmark. This can be the name of an executable or a shell \
|
.help("The command to benchmark. This can be the name of an executable, a command \
|
||||||
command like \"sleep 0.5 && echo test\". If multiple commands are given, \
|
line like \"grep -i todo\" or a shell command like \"sleep 0.5 && echo test\". \
|
||||||
hyperfine will show a comparison of the respective runtimes.")
|
The latter is only available if the shell is not explicitly disabled via \
|
||||||
|
'--shell=none'. If multiple commands are given, hyperfine will show a \
|
||||||
|
comparison of the respective runtimes.")
|
||||||
.required(true)
|
.required(true)
|
||||||
.multiple_occurrences(true)
|
.multiple_occurrences(true)
|
||||||
.forbid_empty_values(true),
|
.forbid_empty_values(true),
|
||||||
@@ -181,7 +183,19 @@ fn build_command() -> Command<'static> {
|
|||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.value_name("SHELL")
|
.value_name("SHELL")
|
||||||
.overrides_with("shell")
|
.overrides_with("shell")
|
||||||
.help("Set the shell to use for executing benchmarked commands."),
|
.help("Set the shell to use for executing benchmarked commands. 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 patform. Finally, this 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.")
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::new("no-shell")
|
||||||
|
.short('N')
|
||||||
|
.conflicts_with_all(&["shell", "debug-mode"])
|
||||||
|
.help("An alias for '--shell=none'.")
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("ignore-failure")
|
Arg::new("ignore-failure")
|
||||||
|
|||||||
+11
-7
@@ -282,13 +282,17 @@ impl Options {
|
|||||||
OutputStyleOption::Disabled => {}
|
OutputStyleOption::Disabled => {}
|
||||||
};
|
};
|
||||||
|
|
||||||
options.executor_kind = match (matches.is_present("debug-mode"), matches.value_of("shell"))
|
options.executor_kind = if matches.is_present("no-shell") {
|
||||||
{
|
ExecutorKind::Raw
|
||||||
(false, Some(shell)) if shell == "default" => ExecutorKind::Shell(Shell::default()),
|
} else {
|
||||||
(false, Some(shell)) => ExecutorKind::Shell(Shell::parse_from_str(shell)?),
|
match (matches.is_present("debug-mode"), matches.value_of("shell")) {
|
||||||
(false, None) => ExecutorKind::Raw,
|
(false, Some(shell)) if shell == "default" => ExecutorKind::Shell(Shell::default()),
|
||||||
(true, Some(shell)) => ExecutorKind::Mock(Some(shell.into())),
|
(false, Some(shell)) if shell == "none" => ExecutorKind::Raw,
|
||||||
(true, None) => ExecutorKind::Mock(None),
|
(false, Some(shell)) => ExecutorKind::Shell(Shell::parse_from_str(shell)?),
|
||||||
|
(false, None) => ExecutorKind::Shell(Shell::default()),
|
||||||
|
(true, Some(shell)) => ExecutorKind::Mock(Some(shell.into())),
|
||||||
|
(true, None) => ExecutorKind::Mock(None),
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if matches.is_present("ignore-failure") {
|
if matches.is_present("ignore-failure") {
|
||||||
|
|||||||
@@ -11,9 +11,3 @@ pub fn hyperfine_raw_command() -> Command {
|
|||||||
pub fn hyperfine() -> assert_cmd::Command {
|
pub fn hyperfine() -> assert_cmd::Command {
|
||||||
assert_cmd::Command::from_std(hyperfine_raw_command())
|
assert_cmd::Command::from_std(hyperfine_raw_command())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hyperfine_shell() -> assert_cmd::Command {
|
|
||||||
let mut cmd = hyperfine();
|
|
||||||
cmd.arg("--shell=default");
|
|
||||||
cmd
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,7 @@ use std::{fs::File, io::Read, path::PathBuf};
|
|||||||
use tempfile::{tempdir, TempDir};
|
use tempfile::{tempdir, TempDir};
|
||||||
|
|
||||||
mod common;
|
mod common;
|
||||||
use common::hyperfine_shell;
|
use common::hyperfine;
|
||||||
|
|
||||||
struct ExecutionOrderTest {
|
struct ExecutionOrderTest {
|
||||||
cmd: assert_cmd::Command,
|
cmd: assert_cmd::Command,
|
||||||
@@ -19,7 +19,7 @@ impl ExecutionOrderTest {
|
|||||||
let logfile_path = tempdir.path().join("output.log");
|
let logfile_path = tempdir.path().join("output.log");
|
||||||
|
|
||||||
ExecutionOrderTest {
|
ExecutionOrderTest {
|
||||||
cmd: hyperfine_shell(),
|
cmd: hyperfine(),
|
||||||
expected_content: String::new(),
|
expected_content: String::new(),
|
||||||
logfile_path,
|
logfile_path,
|
||||||
tempdir,
|
tempdir,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
mod common;
|
mod common;
|
||||||
use common::{hyperfine, hyperfine_shell};
|
use common::hyperfine;
|
||||||
|
|
||||||
use predicates::prelude::*;
|
use predicates::prelude::*;
|
||||||
|
|
||||||
@@ -86,19 +86,20 @@ fn fails_for_unknown_command() {
|
|||||||
.assert()
|
.assert()
|
||||||
.failure()
|
.failure()
|
||||||
.stderr(predicate::str::contains(
|
.stderr(predicate::str::contains(
|
||||||
"Failed to run command 'some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577'",
|
"Command terminated with non-zero exit code",
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn fails_for_unknown_shell_command() {
|
fn fails_for_unknown_command_without_shell() {
|
||||||
hyperfine_shell()
|
hyperfine()
|
||||||
|
.arg("--shell=none")
|
||||||
.arg("--runs=1")
|
.arg("--runs=1")
|
||||||
.arg("some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577")
|
.arg("some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577")
|
||||||
.assert()
|
.assert()
|
||||||
.failure()
|
.failure()
|
||||||
.stderr(predicate::str::contains(
|
.stderr(predicate::str::contains(
|
||||||
"Command terminated with non-zero exit code",
|
"Failed to run command 'some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577'",
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user