Skip to content
Myr

Better error handling in run_intermediate_command

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Peter · committed by David Peter · parent 662d5ca · Browse files · 2 files+41 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+41 added−7 removed

  • tests:+36 added−0 removed
  • other:+5 added−7 removed

2 files+41 added−7 removed

modified:src/benchmark/scheduler.rs+5 added-7 removed
22 unmodified lines
23use crate::util::exit_code::extract_exit_code;24use crate::util::min_max::{max, min};25use crate::util::units::Second;2627use anyhow::{bail, Result};27use anyhow::{anyhow, bail, Result};2829/////////////// TODO: refactor the following part3031/// Correct for shell spawning time
208 unmodified lines
240 &self,241 command: &Command<'_>,242 error_output: &'static str,243 ) -> Result<TimingResult> {244 let res = time_shell_command(244 time_shell_command(245 &self.options.shell,246 command,247 self.options.command_output_policy,248 CmdFailureAction::RaiseError,249 None,250 );251 if res.is_err() {252 bail!(error_output);253 }254 return res.map(|r| r.0);250 )251 .map(|r| r.0)252 .map_err(|_| anyhow!(error_output))253 }254255 /// Run the command specified by `--setup`.256 fn run_setup_command(
328 unmodified lines
modified:tests/integration_tests.rs+36 added
81 unmodified lines
82 "Command terminated with non-zero exit code",83 ));84}8586#[test]87fn fails_for_unknown_setup_command() {88 hyperfine()89 .arg("--setup=some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577")90 .arg("echo test")91 .assert()92 .failure()93 .stderr(predicate::str::contains(94 "The setup command terminated with a non-zero exit code.",95 ));96}9798#[test]99fn fails_for_unknown_cleanup_command() {100 hyperfine()101 .arg("--cleanup=some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577")102 .arg("echo test")103 .assert()104 .failure()105 .stderr(predicate::str::contains(106 "The cleanup command terminated with a non-zero exit code.",107 ));108}109110#[test]111fn fails_for_unknown_prepare_command() {112 hyperfine()113 .arg("--prepare=some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577")114 .arg("echo test")115 .assert()116 .failure()117 .stderr(predicate::str::contains(118 "The preparation command terminated with a non-zero exit code.",119 ));120}121122#[cfg(unix)]123#[test]124fn can_run_failing_commands_with_ignore_failure_option() {125 hyperfine()
14 unmodified lines