viewpoint_test/error/
mod.rs

1//! Error types for the test framework.
2
3use thiserror::Error;
4
5/// Errors that can occur during test execution.
6#[derive(Debug, Error)]
7pub enum TestError {
8    /// Error from the core browser automation library.
9    #[error("Core error: {0}")]
10    Core(#[from] viewpoint_core::CoreError),
11
12    /// Error during test harness setup.
13    #[error("Harness setup failed: {0}")]
14    Setup(String),
15
16    /// Error during test harness cleanup.
17    #[error("Harness cleanup failed: {0}")]
18    Cleanup(String),
19
20    /// Assertion failed.
21    #[error("Assertion failed: {0}")]
22    Assertion(#[from] AssertionError),
23
24    /// Timeout exceeded.
25    #[error("Timeout exceeded after {0:?}")]
26    Timeout(std::time::Duration),
27}
28
29/// Error type for failed assertions.
30#[derive(Debug, Error)]
31#[error("{message}\n  Expected: {expected}\n  Actual: {actual}")]
32pub struct AssertionError {
33    /// Description of what was being asserted.
34    pub message: String,
35    /// The expected value.
36    pub expected: String,
37    /// The actual value.
38    pub actual: String,
39}
40
41impl AssertionError {
42    /// Create a new assertion error.
43    pub fn new(message: impl Into<String>, expected: impl Into<String>, actual: impl Into<String>) -> Self {
44        Self {
45            message: message.into(),
46            expected: expected.into(),
47            actual: actual.into(),
48        }
49    }
50}