/
githubmirror
/
fd
Обзор
Документация
Войти
/
githubmirror
/
fd
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
v7.5.0
src/exit_codes.rs
59 строк
1 KB
fusillicode
Add unit tests for merge_exitcodes
22 фев 2020, 14:32
22 фев 2020, 14:32
0f2429c
Код
Авторство
О чём код?
#[derive(PartialEq, Debug)] pub enum ExitCode { Success, GeneralError, KilledBySigint, } impl Into<i32> for ExitCode { fn into(self) -> i32 { match self { ExitCode::Success => 0, ExitCode::GeneralError => 1, ExitCode::KilledBySigint => 130, } } } impl ExitCode { fn is_error(&self) -> bool { match self { ExitCode::GeneralError | ExitCode::KilledBySigint => true, _ => false, } } } pub fn merge_exitcodes(results: Vec<ExitCode>) -> ExitCode { if results.iter().any(ExitCode::is_error) { return ExitCode::GeneralError; } ExitCode::Success } #[cfg(test)] mod tests { use super::*; #[test] fn success_with_empty_vec() { assert_eq!(merge_exitcodes(vec![]), ExitCode::Success); } #[test] fn general_error_with_at_least_a_matching_error() { assert_eq!( merge_exitcodes(vec![ExitCode::KilledBySigint, ExitCode::Success]), ExitCode::GeneralError ); assert_eq!( merge_exitcodes(vec![ExitCode::GeneralError, ExitCode::Success]), ExitCode::GeneralError ); } #[test] fn success_with_no_error() { assert_eq!(merge_exitcodes(vec![ExitCode::Success]), ExitCode::Success); } }