MCPcopy Index your code
hub / github.com/carllerche/assert-struct / capture_panic_message

Function capture_panic_message

assert-struct/tests/util/mod.rs:7–16  ·  view source on GitHub ↗

Captures the panic message from a function that should panic. Forces plain (non-colored) output so snapshots are stable across environments.

(f: F)

Source from the content-addressed store, hash-verified

5/// Captures the panic message from a function that should panic.
6/// Forces plain (non-colored) output so snapshots are stable across environments.
7pub 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]

Callers

nothing calls this directly

Calls 1

as_strMethod · 0.80

Tested by

no test coverage detected