Skip to content
Myr

Respect exit codes with `--exec-batch`

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

authored by amesgen · committed by amesgen · parent 0984ed9 · Browse files · 2 files+27 added−3 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+27 added−3 removed

  • tests:+16 added−0 removed
  • other:+11 added−3 removed

2 files+27 added−3 removed

modified:src/exec/mod.rs+11 added-3 removed
14 unmodified lines
15use argmax::Command;16use once_cell::sync::Lazy;17use regex::Regex;1819use crate::exit_codes::ExitCode;19use crate::exit_codes::{merge_exitcodes, ExitCode};2021use self::command::{execute_commands, handle_cmd_error};22use self::input::{basename, dirname, remove_extension};23pub use self::job::{batch, job};
95 unmodified lines
119 return handle_cmd_error(Some(&builder.cmd), e);120 }121 }122123 ExitCode::Success123 merge_exitcodes(builders.iter().map(|b| b.exit_code()))124 }125 Err(e) => handle_cmd_error(None, e),126 }127 }
7 unmodified lines
135 post_args: Vec<OsString>,136 cmd: Command,137 count: usize,138 limit: usize,139 exit_code: ExitCode,140}141142impl CommandBuilder {143 fn new(template: &CommandTemplate, limit: usize) -> io::Result<Self> {
19 unmodified lines
163 post_args,164 cmd,165 count: 0,166 limit,167 exit_code: ExitCode::Success,168 })169 }170171 fn new_command(pre_args: &[OsString]) -> io::Result<Command> {
25 unmodified lines
197198 fn finish(&mut self) -> io::Result<()> {199 if self.count > 0 {200 self.cmd.try_args(&self.post_args)?;199 self.cmd.status()?;201 if !self.cmd.status()?.success() {202 self.exit_code = ExitCode::GeneralError;203 }204205 self.cmd = Self::new_command(&self.pre_args)?;206 self.count = 0;207 }208209 Ok(())210 }211212 fn exit_code(&self) -> ExitCode {213 self.exit_code214 }215}216217/// Represents a template that is utilized to generate command strings.218///
383 unmodified lines
modified:tests/tests.rs+16 added
1494 unmodified lines
1495 te.assert_failure_with_error(1496 &["foo", "--exec-batch", "echo {}"],1497 "[fd error]: First argument of exec-batch is expected to be a fixed executable",1498 );14991500 te.assert_failure_with_error(&["a.foo", "--exec-batch", "bash", "-c", "exit 1"], "");1501 }1502}15031504#[test]
47 unmodified lines
1552 "directory_foo"1553 ],1554 ]1555 );15561557 te.assert_failure_with_error(1558 &[1559 "a.foo",1560 "--exec-batch",1561 "echo",1562 ";",1563 "--exec-batch",1564 "bash",1565 "-c",1566 "exit 1",1567 ],1568 "",1569 );1570}15711572#[test]1573fn test_exec_batch_with_limit() {
585 unmodified lines