]>
git.proxmox.com Git - rustc.git/blob - vendor/anyhow/tests/test_fmt.rs
1 use anyhow
::{bail, Context, Result}
;
5 bail
!(io
::Error
::new(io
::ErrorKind
::PermissionDenied
, "oh no!"));
9 f().context("f failed")
12 fn h() -> Result
<()> {
13 g().context("g failed")
16 const EXPECTED_ALTDISPLAY_F
: &str = "oh no!";
18 const EXPECTED_ALTDISPLAY_G
: &str = "f failed: oh no!";
20 const EXPECTED_ALTDISPLAY_H
: &str = "g failed: f failed: oh no!";
22 const EXPECTED_DEBUG_F
: &str = "oh no!";
24 const EXPECTED_DEBUG_G
: &str = "\
31 const EXPECTED_DEBUG_H
: &str = "\
39 const EXPECTED_ALTDEBUG_F
: &str = "\
41 kind: PermissionDenied,
46 const EXPECTED_ALTDEBUG_G
: &str = "\
48 context: \"f failed\",
50 kind: PermissionDenied,
56 const EXPECTED_ALTDEBUG_H
: &str = "\
58 context: \"g failed\",
60 context: \"f failed\",
62 kind: PermissionDenied,
71 assert_eq
!("g failed", h().unwrap_err().to_string());
75 fn test_altdisplay() {
76 assert_eq
!(EXPECTED_ALTDISPLAY_F
, format
!("{:#}", f().unwrap_err()));
77 assert_eq
!(EXPECTED_ALTDISPLAY_G
, format
!("{:#}", g().unwrap_err()));
78 assert_eq
!(EXPECTED_ALTDISPLAY_H
, format
!("{:#}", h().unwrap_err()));
82 #[cfg_attr(not(backtrace), ignore)]
84 assert_eq
!(EXPECTED_DEBUG_F
, format
!("{:?}", f().unwrap_err()));
85 assert_eq
!(EXPECTED_DEBUG_G
, format
!("{:?}", g().unwrap_err()));
86 assert_eq
!(EXPECTED_DEBUG_H
, format
!("{:?}", h().unwrap_err()));
91 assert_eq
!(EXPECTED_ALTDEBUG_F
, format
!("{:#?}", f().unwrap_err()));
92 assert_eq
!(EXPECTED_ALTDEBUG_G
, format
!("{:#?}", g().unwrap_err()));
93 assert_eq
!(EXPECTED_ALTDEBUG_H
, format
!("{:#?}", h().unwrap_err()));