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
Provenance
- Commit
cb95f1d- Tree
29b3b29- Author
amesgen <amesgen@amesgen.de>- Committer
amesgen <amesgen@amesgen.de>- Parent
0984ed9
2 files changed+27 added−3 removed
modified:src/exec/mod.rs+11 added-3 removed
14 unmodified lines15 use argmax::Command;16 use once_cell::sync::Lazy;17 use regex::Regex;18 19-use crate::exit_codes::ExitCode;19+use crate::exit_codes::{merge_exitcodes, ExitCode};20 21 use self::command::{execute_commands, handle_cmd_error};22 use self::input::{basename, dirname, remove_extension};23 pub use self::job::{batch, job};95 unmodified lines119 return handle_cmd_error(Some(&builder.cmd), e);120 }121 }122 123- ExitCode::Success123+ merge_exitcodes(builders.iter().map(|b| b.exit_code()))124 }125 Err(e) => handle_cmd_error(None, e),126 }127 }7 unmodified lines135 post_args: Vec<OsString>,136 cmd: Command,137 count: usize,138 limit: usize,139+ exit_code: ExitCode,140 }141 142 impl CommandBuilder {143 fn new(template: &CommandTemplate, limit: usize) -> io::Result<Self> {19 unmodified lines163 post_args,164 cmd,165 count: 0,166 limit,167+ exit_code: ExitCode::Success,168 })169 }170 171 fn new_command(pre_args: &[OsString]) -> io::Result<Command> {25 unmodified lines197 198 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+ }204 205 self.cmd = Self::new_command(&self.pre_args)?;206 self.count = 0;207 }208 209 Ok(())210 }211+212+ fn exit_code(&self) -> ExitCode {213+ self.exit_code214+ }215 }216 217 /// Represents a template that is utilized to generate command strings.218 ///383 unmodified linesmodified:tests/tests.rs+16 added
1494 unmodified lines1495 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 );1499+1500+ te.assert_failure_with_error(&["a.foo", "--exec-batch", "bash", "-c", "exit 1"], "");1501 }1502 }1503 1504 #[test]47 unmodified lines1552 "directory_foo"1553 ],1554 ]1555 );1556+1557+ 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 }1571 1572 #[test]1573 fn test_exec_batch_with_limit() {585 unmodified lines