Skip to content
Myr

Add test of Display and Debug impls

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Tolnay · committed by David Tolnay · parent abd2452 · Browse files · 1 file+50 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+50 added−0 removed

  • tests:+50 added−0 removed

1 file+50 added−0 removed

added:tests/test_fmt.rs+50 added
1use anyhow::{bail, Context, Result};23fn f() -> Result<()> {4 bail!("oh no!");5}67fn g() -> Result<()> {8 f().context("f failed")9}1011fn h() -> Result<()> {12 g().context("g failed")13}1415const EXPECTED_DEBUG_F: &str = "\16oh no!1718Backtrace disabled; run with RUST_LIB_BACKTRACE=1 environment variable to display a backtrace19";2021const EXPECTED_DEBUG_G: &str = "\22f failed2324Caused by:25 oh no!2627Backtrace disabled; run with RUST_LIB_BACKTRACE=1 environment variable to display a backtrace28";2930const EXPECTED_DEBUG_H: &str = "\31g failed3233Caused by:34 0: f failed35 1: oh no!3637Backtrace disabled; run with RUST_LIB_BACKTRACE=1 environment variable to display a backtrace38";3940#[test]41fn test_display() {42 assert_eq!("g failed", h().unwrap_err().to_string());43}4445#[test]46fn test_debug() {47 assert_eq!(EXPECTED_DEBUG_F, format!("{:?}", f().unwrap_err()));48 assert_eq!(EXPECTED_DEBUG_G, format!("{:?}", g().unwrap_err()));49 assert_eq!(EXPECTED_DEBUG_H, format!("{:?}", h().unwrap_err()));50}