Add unit tests for merge_exitcodes

This commit is contained in:
fusillicode 2020-02-22 10:39:03 +01:00 committed by David Peter
parent 232e3937f2
commit 0f2429cabc
3 changed files with 30 additions and 2 deletions

View File

@ -7,7 +7,7 @@
// according to those terms.
use super::CommandTemplate;
use crate::exit_codes::{ExitCode, merge_exitcodes};
use crate::exit_codes::{merge_exitcodes, ExitCode};
use crate::walk::WorkerResult;
use std::path::PathBuf;
use std::sync::mpsc::Receiver;

View File

@ -1,3 +1,4 @@
#[derive(PartialEq, Debug)]
pub enum ExitCode {
Success,
GeneralError,
@ -29,3 +30,30 @@ pub fn merge_exitcodes(results: Vec<ExitCode>) -> ExitCode {
}
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);
}
}

View File

@ -7,7 +7,7 @@
// according to those terms.
use crate::exec;
use crate::exit_codes::{ExitCode, merge_exitcodes};
use crate::exit_codes::{merge_exitcodes, ExitCode};
use crate::fshelper;
use crate::internal::{opts::FdOptions, osstr_to_bytes, MAX_BUFFER_LENGTH};
use crate::output;