use klauthed_macros::DomainError;
#[derive(Debug, DomainError)]
#[domain(prefix = "testing", category = "internal")]
#[non_exhaustive]
pub enum TestingError {
Fixture(String),
}
impl std::fmt::Display for TestingError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
TestingError::Fixture(msg) => write!(f, "failed to build fixture: {msg}"),
}
}
}
impl std::error::Error for TestingError {}
#[cfg(test)]
mod tests {
use super::*;
use klauthed_error::{DomainError, ErrorCategory};
#[test]
fn fixture_error_is_internal() {
let err = TestingError::Fixture("nope".into());
assert_eq!(err.category(), ErrorCategory::Internal);
assert_eq!(err.code().as_str(), "testing.fixture");
assert!(err.to_string().contains("nope"));
}
}