]> git.proxmox.com Git - rustc.git/blob - vendor/anyhow/tests/test_convert.rs
New upstream version 1.55.0+dfsg1
[rustc.git] / vendor / anyhow / tests / test_convert.rs
1 #![allow(clippy::unnecessary_wraps)]
2
3 mod drop;
4
5 use self::drop::{DetectDrop, Flag};
6 use anyhow::{Error, Result};
7 use std::error::Error as StdError;
8
9 #[test]
10 fn test_convert() {
11 let has_dropped = Flag::new();
12 let error = Error::new(DetectDrop::new(&has_dropped));
13 let box_dyn = Box::<dyn StdError>::from(error);
14 assert_eq!("oh no!", box_dyn.to_string());
15 drop(box_dyn);
16 assert!(has_dropped.get());
17 }
18
19 #[test]
20 fn test_convert_send() {
21 let has_dropped = Flag::new();
22 let error = Error::new(DetectDrop::new(&has_dropped));
23 let box_dyn = Box::<dyn StdError + Send>::from(error);
24 assert_eq!("oh no!", box_dyn.to_string());
25 drop(box_dyn);
26 assert!(has_dropped.get());
27 }
28
29 #[test]
30 fn test_convert_send_sync() {
31 let has_dropped = Flag::new();
32 let error = Error::new(DetectDrop::new(&has_dropped));
33 let box_dyn = Box::<dyn StdError + Send + Sync>::from(error);
34 assert_eq!("oh no!", box_dyn.to_string());
35 drop(box_dyn);
36 assert!(has_dropped.get());
37 }
38
39 #[test]
40 fn test_question_mark() -> Result<(), Box<dyn StdError>> {
41 fn f() -> Result<()> {
42 Ok(())
43 }
44 f()?;
45 Ok(())
46 }