MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / backtrace

Function backtrace

crates/core/tests/tests.rs:215–246  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

213#[test]
214#[cfg(feature = "backtrace")]
215fn backtrace() {
216 // Backtrace on OOM.
217 let e = Error::from(OutOfMemory::new(5));
218 assert_eq!(e.backtrace().status(), BacktraceStatus::Disabled);
219
220 let backtraces_enabled =
221 match std::env::var("RUST_LIB_BACKTRACE").or_else(|_| std::env::var("RUST_BACKTRACE")) {
222 Err(_) => false,
223 Ok(s) if s == "0" => false,
224 Ok(_) => true,
225 };
226
227 let assert_backtrace = |e: Error| {
228 if backtraces_enabled {
229 assert!(matches!(
230 e.backtrace().status(),
231 BacktraceStatus::Unsupported | BacktraceStatus::Captured
232 ));
233 } else {
234 assert_eq!(e.backtrace().status(), BacktraceStatus::Disabled);
235 }
236 };
237
238 // Backtrace on `Error::msg`.
239 assert_backtrace(Error::msg("whoops"));
240
241 // Backtrace on `Error::new`.
242 assert_backtrace(Error::new(TestError(42)));
243
244 // Backtrace on context chain.
245 assert_backtrace(Error::new(TestError(42)).context("yikes"));
246}
247
248#[test]
249fn format_err_macro_string_literal() {

Callers

nothing calls this directly

Calls 5

fromFunction · 0.85
msgFunction · 0.85
newFunction · 0.70
TestErrorClass · 0.70
contextMethod · 0.45

Tested by

no test coverage detected