From bd0bd70ae76ec7a9148efbb149ee1a4ae38bc4b8 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 5 Sep 2022 18:44:02 -0700 Subject: [PATCH] Add test of getting backtrace from an anyhow source --- Cargo.toml | 2 +- tests/test_backtrace.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 1ec63cc..9ebb732 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ rust-version = "1.31" thiserror-impl = { version = "=1.0.34", path = "impl" } [dev-dependencies] -anyhow = "1.0" +anyhow = "1.0.64" ref-cast = "1.0" rustversion = "1.0" trybuild = { version = "1.0.49", features = ["diff"] } diff --git a/tests/test_backtrace.rs b/tests/test_backtrace.rs index 052c6f4..d70f483 100644 --- a/tests/test_backtrace.rs +++ b/tests/test_backtrace.rs @@ -86,6 +86,13 @@ pub mod structs { backtrace: Arc, } + #[derive(Error, Debug)] + #[error("...")] + pub struct AnyhowBacktrace { + #[backtrace] + source: anyhow::Error, + } + #[test] fn test_backtrace() { let error = PlainBacktrace { @@ -121,6 +128,11 @@ pub mod structs { let error = ArcBacktraceFrom::from(Inner); assert!(any::request_ref::(&error).is_some()); + + let error = AnyhowBacktrace { + source: anyhow::Error::msg("..."), + }; + assert!(any::request_ref::(&error).is_some()); } }