Skip to main content

klauthed_testing/
error.rs

1//! Error type for the testing utilities (`TestingError`).
2
3use klauthed_macros::DomainError;
4
5/// Errors raised by the testing utilities themselves.
6///
7/// These are rare — most helpers are infallible — but a few operations (e.g.
8/// constructing fixtures from malformed input) can fail, and they report through
9/// the shared [`DomainError`](klauthed_error::DomainError) contract like every
10/// other klauthed error.
11#[derive(Debug, DomainError)]
12#[domain(prefix = "testing", category = "internal")]
13#[non_exhaustive]
14pub enum TestingError {
15    /// A fixture could not be built from the provided input.
16    Fixture(String),
17}
18
19impl std::fmt::Display for TestingError {
20    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21        match self {
22            TestingError::Fixture(msg) => write!(f, "failed to build fixture: {msg}"),
23        }
24    }
25}
26
27impl std::error::Error for TestingError {}
28
29#[cfg(test)]
30mod tests {
31    use super::*;
32    use klauthed_error::{DomainError, ErrorCategory};
33
34    #[test]
35    fn fixture_error_is_internal() {
36        let err = TestingError::Fixture("nope".into());
37        assert_eq!(err.category(), ErrorCategory::Internal);
38        assert_eq!(err.code().as_str(), "testing.fixture");
39        assert!(err.to_string().contains("nope"));
40    }
41}