orion_error/
testcase.rs

1// 测试专用断言 (无消息)
2pub trait TestAssert {
3    type Output;
4    fn assert(self) -> Self::Output;
5}
6
7// 测试专用断言 (带消息)
8pub trait TestAssertWithMsg<A> {
9    type Output;
10    fn assert(self, msg: A) -> Self::Output;
11}
12
13impl<T, E> TestAssert for Result<T, E>
14where
15    E: std::fmt::Display,
16{
17    type Output = T;
18
19    fn assert(self) -> T {
20        self.unwrap_or_else(|e| panic!("[TEST ASSERTION FAILED] \n Error details: {}", e))
21    }
22}
23
24impl<T, E> TestAssertWithMsg<&str> for Result<T, E>
25where
26    E: std::fmt::Display,
27{
28    type Output = T;
29
30    fn assert(self, msg: &str) -> T {
31        self.unwrap_or_else(|e| panic!("[TEST ASSERTION FAILED] {} \n Error details: {}", msg, e))
32    }
33}
34
35impl<T> TestAssert for Option<T> {
36    type Output = T;
37
38    fn assert(self) -> T {
39        self.unwrap_or_else(|| panic!("[OPTION ASSERTION FAILED] ",))
40    }
41}