use serde::{Deserialize, Serialize};
pub trait TestError: std::error::Error {
fn fails(&self) -> bool { true }
fn exitcode(&self) -> (u8, u64) { (2, 0) }
fn additional_details(&self) -> Option<String> { None }
fn print_cli(&self) -> String {
use colored::Colorize;
format!("{}", self).red().to_string()
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct TestErrorDetails {
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,
}
}
}
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 {}