|
1 |
| -#[derive(Default, PartialEq, PartialOrd, Debug)] |
2 |
| -pub struct Error { |
3 |
| - message: String, |
4 |
| -} |
| 1 | +/// A generic error type that is returned from all tests. |
| 2 | +/// |
| 3 | +/// This type can polymorphically take the form of any type that implements |
| 4 | +/// [`Error`], which allows any and all generic errors to be a valid return type |
| 5 | +/// from tests. |
| 6 | +/// |
| 7 | +/// [`Error`]: std::error::Error |
| 8 | +pub type Error = Box<dyn std::error::Error>; |
5 | 9 |
|
6 |
| -impl std::fmt::Display for Error { |
7 |
| - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
8 |
| - self.message.fmt(f) |
9 |
| - } |
10 |
| -} |
11 |
| - |
12 |
| -impl std::error::Error for Error {} |
13 |
| - |
14 |
| -impl Error { |
15 |
| - pub fn from_error<T: std::error::Error>(e: T) -> Self { |
16 |
| - Self { |
17 |
| - message: e.to_string(), |
18 |
| - } |
19 |
| - } |
20 |
| - |
21 |
| - pub fn new() -> Self { |
22 |
| - Self::default() |
23 |
| - } |
24 |
| -} |
25 |
| - |
26 |
| -impl<T> From<T> for Error |
27 |
| -where |
28 |
| - String: From<T>, |
29 |
| -{ |
30 |
| - fn from(value: T) -> Self { |
31 |
| - Self { |
32 |
| - message: String::from(value), |
33 |
| - } |
34 |
| - } |
35 |
| -} |
36 |
| - |
37 |
| -/// A result type for unit tests. |
| 10 | +/// A [`Result`] object returned from utilities in this test framework. |
| 11 | +/// |
| 12 | +/// This uses the generic [`Error`] implementation to ensure that it can return |
| 13 | +/// any and all error objects back from test-cases. |
| 14 | +/// |
| 15 | +/// [`Result`]: std::result::Result |
38 | 16 | pub type Result<T> = ::std::result::Result<T, Error>;
|
39 | 17 |
|
40 |
| -/// The result that is either implicitly or explicitly returned from tests. |
| 18 | +/// A [`Result`] object returned from all tests, either implicitly or explicitly. |
| 19 | +/// |
| 20 | +/// All test results can only successfully return unit `()` objects, and so this |
| 21 | +/// `TestResult` type pins the return type. |
41 | 22 | pub type TestResult = crate::Result<()>;
|
0 commit comments