mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-02 17:11:28 +00:00
Improve command and hook failure diagnostics
This commit is contained in:
1 parent
e4a3213bf3
commit
63209515a3
3 files changed
+89
-59
No files matched your search
+47
-19
@@ -275,7 +275,7 @@ fn fails_for_unknown_command() {
|
||||
.assert()
|
||||
.failure()
|
||||
.stderr(predicate::str::contains(
|
||||
"Command terminated with non-zero exit code",
|
||||
"Command 'some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577' terminated with non-zero exit code",
|
||||
));
|
||||
}
|
||||
|
||||
@@ -298,12 +298,15 @@ fn fails_for_failing_command_without_shell() {
|
||||
hyperfine()
|
||||
.arg("--shell=none")
|
||||
.arg("--runs=1")
|
||||
.arg("false")
|
||||
.arg("--command-name=named benchmark")
|
||||
.args(["--parameter-list", "status", "0,1"])
|
||||
.arg("test {status} -eq 0")
|
||||
.assert()
|
||||
.failure()
|
||||
.stderr(predicate::str::contains(
|
||||
"Command terminated with non-zero exit code",
|
||||
));
|
||||
"Command 'test 1 -eq 0' terminated with non-zero exit code 1 in the first benchmark run.",
|
||||
))
|
||||
.stderr(predicate::str::contains("--ignore-failure"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -315,9 +318,7 @@ fn fails_for_unknown_setup_command() {
|
||||
.arg("echo test")
|
||||
.assert()
|
||||
.failure()
|
||||
.stderr(predicate::str::contains(
|
||||
"The setup command terminated with a non-zero exit code.",
|
||||
));
|
||||
.stderr(predicate::str::contains("The setup command failed."));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -329,9 +330,7 @@ fn fails_for_unknown_cleanup_command() {
|
||||
.arg("echo test")
|
||||
.assert()
|
||||
.failure()
|
||||
.stderr(predicate::str::contains(
|
||||
"The cleanup command terminated with a non-zero exit code.",
|
||||
));
|
||||
.stderr(predicate::str::contains("The cleanup command failed."));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -342,9 +341,7 @@ fn fails_for_unknown_prepare_command() {
|
||||
.arg("echo test")
|
||||
.assert()
|
||||
.failure()
|
||||
.stderr(predicate::str::contains(
|
||||
"The preparation command terminated with a non-zero exit code.",
|
||||
));
|
||||
.stderr(predicate::str::contains("The preparation command failed."));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -355,9 +352,40 @@ fn fails_for_unknown_conclude_command() {
|
||||
.arg("echo test")
|
||||
.assert()
|
||||
.failure()
|
||||
.stderr(predicate::str::contains(
|
||||
"The conclusion command terminated with a non-zero exit code.",
|
||||
));
|
||||
.stderr(predicate::str::contains("The conclusion command failed."));
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn hook_errors_preserve_causes_and_explain_shell_syntax() {
|
||||
for hook in ["--setup", "--prepare", "--conclude", "--cleanup"] {
|
||||
for (command, cause) in [
|
||||
(
|
||||
"some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577",
|
||||
"No such file or directory",
|
||||
),
|
||||
("printf 'unclosed", "missing closing quote"),
|
||||
("false", "terminated with non-zero exit code 1"),
|
||||
] {
|
||||
let assert = hyperfine()
|
||||
.args(["--runs=1", hook, command, "true"])
|
||||
.assert()
|
||||
.failure()
|
||||
.stderr(predicate::str::contains(command))
|
||||
.stderr(predicate::str::contains(cause))
|
||||
.stderr(predicate::str::contains("'-S'/'--shell=default'"))
|
||||
.stderr(predicate::str::contains("append ' || true'"))
|
||||
.stderr(predicate::str::contains("--ignore-failure").not());
|
||||
if command != "false" {
|
||||
assert.stderr(predicate::str::contains("non-zero exit code").not());
|
||||
}
|
||||
}
|
||||
|
||||
hyperfine()
|
||||
.args(["-S", "--runs=1", hook, "false || true", "true"])
|
||||
.assert()
|
||||
.success();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
@@ -368,7 +396,7 @@ fn can_run_failing_commands_with_ignore_failure_option() {
|
||||
.assert()
|
||||
.failure()
|
||||
.stderr(predicate::str::contains(
|
||||
"Command terminated with non-zero exit code",
|
||||
"Command 'false' terminated with non-zero exit code",
|
||||
));
|
||||
|
||||
hyperfine()
|
||||
@@ -400,7 +428,7 @@ fn can_ignore_specific_exit_codes() {
|
||||
.assert()
|
||||
.failure()
|
||||
.stderr(predicate::str::contains(
|
||||
"Command terminated with non-zero exit code 2",
|
||||
"Command 'exit 2' terminated with non-zero exit code 2",
|
||||
));
|
||||
}
|
||||
|
||||
@@ -441,7 +469,7 @@ fn can_ignore_multiple_exit_codes() {
|
||||
.assert()
|
||||
.failure()
|
||||
.stderr(predicate::str::contains(
|
||||
"Command terminated with non-zero exit code 4",
|
||||
"Command 'exit 4' terminated with non-zero exit code 4",
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user