Captures the panic message from a function that should panic. Forces plain (non-colored) output so snapshots are stable across environments.
(f: F)
| 5 | /// Captures the panic message from a function that should panic. |
| 6 | /// Forces plain (non-colored) output so snapshots are stable across environments. |
| 7 | pub fn capture_panic_message<F: FnOnce() + panic::UnwindSafe>(f: F) -> String { |
| 8 | let _guard = assert_struct::__macro_support::PlainOutputGuard::new(); |
| 9 | let result = panic::catch_unwind(f); |
| 10 | let err = result.unwrap_err(); |
| 11 | err.downcast_ref::<String>() |
| 12 | .map(|s| s.as_str()) |
| 13 | .or_else(|| err.downcast_ref::<&str>().copied()) |
| 14 | .unwrap() |
| 15 | .to_string() |
| 16 | } |
| 17 | |
| 18 | /// Macro to reduce boilerplate for error message tests |
| 19 | #[macro_export] |