exit_codes.rs
This file
Path
src/exit_codes.rs
72 lines · 1.7 KiB · Rust
Last changed by
Clean up exit code handlingsharkdpbefore adoptione42ddda
History of this fileTake it
The walk stopped after 200 commits: lines older than 04debe5 point at it.
Clean up exit code handlingsharkdpbefore adoptione42ddda
line 1why, one step back1#[derive(Debug, Clone, Copy, PartialEq)]Adapt READMEsharkdpbefore adoption04debe5
line 2why, one step back2pub enum ExitCode {Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
line 3why, one step back3 Success,Adapt READMEsharkdpbefore adoption04debe5
lines 4–10why, one step back4 GeneralError,5 KilledBySigint,6}78impl Into<i32> for ExitCode {9 fn into(self) -> i32 {10 match self {Switch back from Self to ExitCodefusillicodebefore adoptionb23cfc3
lines 11–13why, one step back11 ExitCode::Success => 0,12 ExitCode::GeneralError => 1,13 ExitCode::KilledBySigint => 130,Adapt READMEsharkdpbefore adoption04debe5
line 14why, one step back14 }Add collection of job & thread exit codes + default to ExitCode::Error if any ExitCode::Errorfusillicodebefore adoption7213f5a
lines 15–18why, one step back15 }16}1718impl ExitCode {Extract ExitCode::is_error helperfusillicodebefore adoptiona5fe138
line 19why, one step back19 fn is_error(&self) -> bool {Clean up exit code handlingsharkdpbefore adoptione42ddda
line 20why, one step back20 *self != ExitCode::SuccessAdapt READMEsharkdpbefore adoption04debe5
line 21why, one step back21 }Extract error_if_any_error as free functionfusillicodebefore adoptione23398e
lines 22–23why, one step back22}23Clean up exit code handlingsharkdpbefore adoptione42ddda
line 24why, one step back24pub fn merge_exitcodes(results: &[ExitCode]) -> ExitCode {Extract error_if_any_error as free functionfusillicodebefore adoptione23398e
lines 25–28why, one step back25 if results.iter().any(ExitCode::is_error) {26 return ExitCode::GeneralError;27 }28 ExitCode::SuccessAdd unit tests for merge_exitcodesfusillicodebefore adoption0f2429c
lines 29–35why, one step back29}3031#[cfg(test)]32mod tests {33 use super::*;3435 #[test]Clean up exit code handlingsharkdpbefore adoptione42ddda
lines 36–37why, one step back36 fn success_when_no_results() {37 assert_eq!(merge_exitcodes(&[]), ExitCode::Success);Add unit tests for merge_exitcodesfusillicodebefore adoption0f2429c
lines 38–40why, one step back38 }3940 #[test]Clean up exit code handlingsharkdpbefore adoptione42ddda
line 41why, one step back41 fn general_error_if_at_least_one_error() {Add unit tests for merge_exitcodesfusillicodebefore adoption0f2429c
line 42why, one step back42 assert_eq!(Clean up exit code handlingsharkdpbefore adoptione42ddda
line 43why, one step back43 merge_exitcodes(&[ExitCode::GeneralError]),Add unit tests for merge_exitcodesfusillicodebefore adoption0f2429c
lines 44–46why, one step back44 ExitCode::GeneralError45 );46 assert_eq!(Clean up exit code handlingsharkdpbefore adoptione42ddda
line 47why, one step back47 merge_exitcodes(&[ExitCode::KilledBySigint]),Add unit tests for merge_exitcodesfusillicodebefore adoption0f2429c
lines 48–49why, one step back48 ExitCode::GeneralError49 );Clean up exit code handlingsharkdpbefore adoptione42ddda
lines 50–61why, one step back50 assert_eq!(51 merge_exitcodes(&[ExitCode::KilledBySigint, ExitCode::Success]),52 ExitCode::GeneralError53 );54 assert_eq!(55 merge_exitcodes(&[ExitCode::Success, ExitCode::GeneralError]),56 ExitCode::GeneralError57 );58 assert_eq!(59 merge_exitcodes(&[ExitCode::GeneralError, ExitCode::KilledBySigint]),60 ExitCode::GeneralError61 );Add unit tests for merge_exitcodesfusillicodebefore adoption0f2429c
lines 62–64why, one step back62 }6364 #[test]Clean up exit code handlingsharkdpbefore adoptione42ddda
lines 65–70why, one step back65 fn success_if_no_error() {66 assert_eq!(merge_exitcodes(&[ExitCode::Success]), ExitCode::Success);67 assert_eq!(68 merge_exitcodes(&[ExitCode::Success, ExitCode::Success]),69 ExitCode::Success70 );Add unit tests for merge_exitcodesfusillicodebefore adoption0f2429c
line 71why, one step back71 }Adapt READMEsharkdpbefore adoption04debe5
line 72why, one step back72}