mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-02 17:11:28 +00:00
Better error handling in run_intermediate_command
This commit is contained in:
1 parent
662d5ca9ac
commit
8c5ae87ca2
2 files changed
+41
-7
No files matched your search
@@ -24,7 +24,7 @@ use crate::util::exit_code::extract_exit_code;
|
|||||||
use crate::util::min_max::{max, min};
|
use crate::util::min_max::{max, min};
|
||||||
use crate::util::units::Second;
|
use crate::util::units::Second;
|
||||||
|
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{anyhow, bail, Result};
|
||||||
|
|
||||||
/////////////// TODO: refactor the following part
|
/////////////// TODO: refactor the following part
|
||||||
|
|
||||||
@@ -241,17 +241,15 @@ impl<'a> Scheduler<'a> {
|
|||||||
command: &Command<'_>,
|
command: &Command<'_>,
|
||||||
error_output: &'static str,
|
error_output: &'static str,
|
||||||
) -> Result<TimingResult> {
|
) -> Result<TimingResult> {
|
||||||
let res = time_shell_command(
|
time_shell_command(
|
||||||
&self.options.shell,
|
&self.options.shell,
|
||||||
command,
|
command,
|
||||||
self.options.command_output_policy,
|
self.options.command_output_policy,
|
||||||
CmdFailureAction::RaiseError,
|
CmdFailureAction::RaiseError,
|
||||||
None,
|
None,
|
||||||
);
|
)
|
||||||
if res.is_err() {
|
.map(|r| r.0)
|
||||||
bail!(error_output);
|
.map_err(|_| anyhow!(error_output))
|
||||||
}
|
|
||||||
return res.map(|r| r.0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Run the command specified by `--setup`.
|
/// Run the command specified by `--setup`.
|
||||||
|
|||||||
@@ -83,6 +83,42 @@ fn fails_for_unknown_command() {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn fails_for_unknown_setup_command() {
|
||||||
|
hyperfine()
|
||||||
|
.arg("--setup=some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577")
|
||||||
|
.arg("echo test")
|
||||||
|
.assert()
|
||||||
|
.failure()
|
||||||
|
.stderr(predicate::str::contains(
|
||||||
|
"The setup command terminated with a non-zero exit code.",
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn fails_for_unknown_cleanup_command() {
|
||||||
|
hyperfine()
|
||||||
|
.arg("--cleanup=some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577")
|
||||||
|
.arg("echo test")
|
||||||
|
.assert()
|
||||||
|
.failure()
|
||||||
|
.stderr(predicate::str::contains(
|
||||||
|
"The cleanup command terminated with a non-zero exit code.",
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn fails_for_unknown_prepare_command() {
|
||||||
|
hyperfine()
|
||||||
|
.arg("--prepare=some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577")
|
||||||
|
.arg("echo test")
|
||||||
|
.assert()
|
||||||
|
.failure()
|
||||||
|
.stderr(predicate::str::contains(
|
||||||
|
"The preparation command terminated with a non-zero exit code.",
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
#[test]
|
#[test]
|
||||||
fn can_run_failing_commands_with_ignore_failure_option() {
|
fn can_run_failing_commands_with_ignore_failure_option() {
|
||||||
|
|||||||
Reference in new issue
Block a user