mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-01 08:50:19 +00:00
Require an explicit shell choice for shell operators
This commit is contained in:
1 parent
4a9e066b41
commit
be4d5dfb18
4 files changed
+282
-2
No files matched your search
@@ -266,6 +266,42 @@ fn fails_with_duplicate_parameter_names() {
|
||||
.stderr(predicate::str::contains("Duplicate parameter names: x"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn requires_explicit_shell_for_shell_syntax() {
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
|
||||
let assert = hyperfine()
|
||||
.current_dir(directory.path())
|
||||
.arg("rm -rf cache/ && ./my_command")
|
||||
.assert()
|
||||
.failure();
|
||||
|
||||
insta::assert_snapshot!(String::from_utf8_lossy(&assert.get_output().stderr), @"
|
||||
Error: Command 'rm -rf cache/ && ./my_command' contains unquoted shell syntax ('&&').
|
||||
Explicitly choose how to execute it:
|
||||
-S / --shell=default Interpret shell syntax.
|
||||
-N / --shell=none Run directly, passing '&&' as a literal argument.
|
||||
");
|
||||
|
||||
hyperfine()
|
||||
.arg("--show-output")
|
||||
.arg("--command-name=benchmark")
|
||||
.args(["--shell=default", "--runs=1", "echo before && echo after"])
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(predicate::str::contains("before"))
|
||||
.stdout(predicate::str::contains("after"))
|
||||
.stdout(predicate::str::contains("&&").not());
|
||||
|
||||
hyperfine()
|
||||
.arg("--show-output")
|
||||
.arg("--command-name=benchmark")
|
||||
.args(["--shell=none", "--runs=1", "echo before && echo after"])
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(predicate::str::contains("before && echo after"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fails_for_unknown_command() {
|
||||
hyperfine()
|
||||
|
||||
Reference in new issue
Block a user