| 675 | } |
| 676 | #[test] |
| 677 | fn fmt_debug_with_single_cause() { |
| 678 | let error = Error::msg("whoops").context("uh oh"); |
| 679 | let actual = format!("{error:?}"); |
| 680 | |
| 681 | // NB: the causes are only numbered when there are multiple of them. |
| 682 | let expected = "\ |
| 683 | uh oh |
| 684 | |
| 685 | Caused by: |
| 686 | whoops |
| 687 | "; |
| 688 | |
| 689 | #[cfg(feature = "backtrace")] |
| 690 | { |
| 691 | assert!(actual.starts_with(expected)); |
| 692 | if let BacktraceStatus::Captured = error.backtrace().status() { |
| 693 | assert!(actual.contains("Stack backtrace:")); |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | #[cfg(not(feature = "backtrace"))] |
| 698 | { |
| 699 | assert_eq!(actual, expected); |
| 700 | } |
| 701 | } |
| 702 | |
| 703 | #[test] |
| 704 | fn fmt_debug_alternate() { |