rtest 0.2.2

integration test building framework
Documentation
use serde::{Deserialize, Serialize};

pub trait TestError: std::error::Error {
    /// Errors might be non-failing, e.g. if some precondition doesn't work you
    /// don't want to set the test to failed
    fn fails(&self) -> bool { true }

    /// ExitCode this error should result on the final binary and the
    /// respective priority, note: Only 1 exitcode is possible, so if multiple
    /// errors eccor, the exitcode with the highest priority is chosen
    fn exitcode(&self) -> (u8, u64) { (2, 0) }

    /// used for cli output
    fn additional_details(&self) -> Option<String> { None }

    /// used for cli output
    fn print_cli(&self) -> String {
        use colored::Colorize;
        format!("{}", self).red().to_string()
    }
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct TestErrorDetails {
    /// Display
    pub message: String,
    pub additional_details: Option<String>,
    pub print_cli: String,
    pub fails: bool,
    pub exitcode_prio: (u8, u64),
}

impl TestErrorDetails {
    pub fn new(error: Box<dyn TestError>) -> Self {
        let fails = error.fails();
        let exitcode_prio = error.exitcode();
        let print_cli = error.print_cli();
        let additional_details = error.additional_details();
        let message = format!("{}", error);
        Self {
            message,
            additional_details,
            print_cli,
            fails,
            exitcode_prio,
        }
    }
}

// TODO
impl PartialEq for TestErrorDetails {
    fn eq(&self, other: &Self) -> bool {
        self.fails == other.fails && self.exitcode_prio == other.exitcode_prio && self.message == other.message
    }
}
impl Eq for TestErrorDetails {}