| 170 | |
| 171 | #[test] |
| 172 | fn is() { |
| 173 | // `is<T>` is true for `Error::msg(T)` |
| 174 | let e = Error::msg("str"); |
| 175 | assert!(e.is::<&str>()); |
| 176 | assert!(!e.is::<TestError>()); |
| 177 | assert!(!e.is::<OutOfMemory>()); |
| 178 | |
| 179 | // `is<T>` is true for `T` in the context chain. |
| 180 | let e = e.context(TestError(42)); |
| 181 | assert!(e.is::<&str>()); |
| 182 | assert!(e.is::<TestError>()); |
| 183 | assert!(!e.is::<OutOfMemory>()); |
| 184 | |
| 185 | // `is<T>` is still true when there are multiple `T`s and `U`s in the |
| 186 | // chain. |
| 187 | let e = e.context(TestError(36)).context("another str"); |
| 188 | assert!(e.is::<&str>()); |
| 189 | assert!(e.is::<TestError>()); |
| 190 | assert!(!e.is::<OutOfMemory>()); |
| 191 | |
| 192 | // `is<T>` is true for `Error::from(T)`. |
| 193 | let e = Error::from(TestError(36)); |
| 194 | assert!(e.is::<TestError>()); |
| 195 | assert!(!e.is::<&str>()); |
| 196 | assert!(!e.is::<OutOfMemory>()); |
| 197 | |
| 198 | // `is<T>` is true for `Error::from(OutOfMemory)`. |
| 199 | let e = Error::from(OutOfMemory::new(5)); |
| 200 | assert!(e.is::<OutOfMemory>()); |
| 201 | assert!(!e.is::<TestError>()); |
| 202 | assert!(!e.is::<&str>()); |
| 203 | } |
| 204 | |
| 205 | #[test] |
| 206 | fn is_for_root_cause_with_initial_error_source() { |