Skip to content

Commit

Permalink
Merge pull request #187 from dtolnay/anyhowbacktrace
Browse files Browse the repository at this point in the history
Add test of getting backtrace from an anyhow source
  • Loading branch information
dtolnay committed Sep 6, 2022
2 parents 2df0715 + bd0bd70 commit 2e4576c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -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"] }
Expand Down
12 changes: 12 additions & 0 deletions tests/test_backtrace.rs
Expand Up @@ -86,6 +86,13 @@ pub mod structs {
backtrace: Arc<Backtrace>,
}

#[derive(Error, Debug)]
#[error("...")]
pub struct AnyhowBacktrace {
#[backtrace]
source: anyhow::Error,
}

#[test]
fn test_backtrace() {
let error = PlainBacktrace {
Expand Down Expand Up @@ -121,6 +128,11 @@ pub mod structs {

let error = ArcBacktraceFrom::from(Inner);
assert!(any::request_ref::<Backtrace>(&error).is_some());

let error = AnyhowBacktrace {
source: anyhow::Error::msg("..."),
};
assert!(any::request_ref::<Backtrace>(&error).is_some());
}
}

Expand Down

0 comments on commit 2e4576c

Please sign in to comment.