Skip to content
Myr

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 file

Take it

The walk stopped after 200 commits: lines older than 04debe5 point at it.

Clean up exit code handlingsharkdpbefore adoptione42ddda

line 1why, one step back
1#[derive(Debug, Clone, Copy, PartialEq)]

Adapt READMEsharkdpbefore adoption04debe5

line 2why, one step back
2pub enum ExitCode {

Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd

line 3why, one step back
3 Success,

Adapt READMEsharkdpbefore adoption04debe5

lines 4–10why, one step back
4 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 back
11 ExitCode::Success => 0,
12 ExitCode::GeneralError => 1,13 ExitCode::KilledBySigint => 130,

Adapt READMEsharkdpbefore adoption04debe5

line 14why, one step back
14 }

Add collection of job & thread exit codes + default to ExitCode::Error if any ExitCode::Errorfusillicodebefore adoption7213f5a

lines 15–18why, one step back
15 }
16}1718impl ExitCode {

Extract ExitCode::is_error helperfusillicodebefore adoptiona5fe138

line 19why, one step back
19 fn is_error(&self) -> bool {

Clean up exit code handlingsharkdpbefore adoptione42ddda

line 20why, one step back
20 *self != ExitCode::Success

Adapt READMEsharkdpbefore adoption04debe5

line 21why, one step back
21 }

Extract error_if_any_error as free functionfusillicodebefore adoptione23398e

lines 22–23why, one step back
22}
23

Clean up exit code handlingsharkdpbefore adoptione42ddda

line 24why, one step back
24pub fn merge_exitcodes(results: &[ExitCode]) -> ExitCode {

Extract error_if_any_error as free functionfusillicodebefore adoptione23398e

lines 25–28why, one step back
25 if results.iter().any(ExitCode::is_error) {
26 return ExitCode::GeneralError;27 }28 ExitCode::Success

Add unit tests for merge_exitcodesfusillicodebefore adoption0f2429c

lines 29–35why, one step back
29}
3031#[cfg(test)]32mod tests {33 use super::*;3435 #[test]

Clean up exit code handlingsharkdpbefore adoptione42ddda

lines 36–37why, one step back
36 fn success_when_no_results() {
37 assert_eq!(merge_exitcodes(&[]), ExitCode::Success);

Add unit tests for merge_exitcodesfusillicodebefore adoption0f2429c

lines 38–40why, one step back
38 }
3940 #[test]

Clean up exit code handlingsharkdpbefore adoptione42ddda

line 41why, one step back
41 fn general_error_if_at_least_one_error() {

Add unit tests for merge_exitcodesfusillicodebefore adoption0f2429c

line 42why, one step back
42 assert_eq!(

Clean up exit code handlingsharkdpbefore adoptione42ddda

line 43why, one step back
43 merge_exitcodes(&[ExitCode::GeneralError]),

Add unit tests for merge_exitcodesfusillicodebefore adoption0f2429c

lines 44–46why, one step back
44 ExitCode::GeneralError
45 );46 assert_eq!(

Clean up exit code handlingsharkdpbefore adoptione42ddda

line 47why, one step back
47 merge_exitcodes(&[ExitCode::KilledBySigint]),

Add unit tests for merge_exitcodesfusillicodebefore adoption0f2429c

lines 48–49why, one step back
48 ExitCode::GeneralError
49 );

Clean up exit code handlingsharkdpbefore adoptione42ddda

lines 50–61why, one step back
50 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 back
62 }
6364 #[test]

Clean up exit code handlingsharkdpbefore adoptione42ddda

lines 65–70why, one step back
65 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 back
71 }

Adapt READMEsharkdpbefore adoption04debe5

line 72why, one step back
72}