mirror of
https://github.com/dtolnay/thiserror.git
synced 2025-04-04 13:27:38 +03:00
Merge pull request #101 from dtolnay/backtrace-from
Add test of capturing Backtrace/Option<Backtrace> in a From impl
This commit is contained in:
commit
1baf746f7d
1 changed files with 60 additions and 0 deletions
|
@ -1,7 +1,14 @@
|
|||
#![cfg_attr(thiserror_nightly_testing, feature(backtrace))]
|
||||
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
#[error("...")]
|
||||
pub struct Inner;
|
||||
|
||||
#[cfg(thiserror_nightly_testing)]
|
||||
pub mod structs {
|
||||
use super::Inner;
|
||||
use std::backtrace::Backtrace;
|
||||
use std::error::Error;
|
||||
use std::sync::Arc;
|
||||
|
@ -34,6 +41,24 @@ pub mod structs {
|
|||
backtrace: Arc<Backtrace>,
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
#[error("...")]
|
||||
pub struct BacktraceFrom {
|
||||
#[from]
|
||||
source: Inner,
|
||||
#[backtrace]
|
||||
backtrace: Backtrace,
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
#[error("...")]
|
||||
pub struct OptBacktraceFrom {
|
||||
#[from]
|
||||
source: Inner,
|
||||
#[backtrace]
|
||||
backtrace: Option<Backtrace>,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_backtrace() {
|
||||
let error = PlainBacktrace {
|
||||
|
@ -55,11 +80,18 @@ pub mod structs {
|
|||
backtrace: Arc::new(Backtrace::capture()),
|
||||
};
|
||||
assert!(error.backtrace().is_some());
|
||||
|
||||
let error = BacktraceFrom::from(Inner);
|
||||
assert!(error.backtrace().is_some());
|
||||
|
||||
let error = OptBacktraceFrom::from(Inner);
|
||||
assert!(error.backtrace().is_some());
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(thiserror_nightly_testing)]
|
||||
pub mod enums {
|
||||
use super::Inner;
|
||||
use std::backtrace::Backtrace;
|
||||
use std::error::Error;
|
||||
use std::sync::Arc;
|
||||
|
@ -98,6 +130,28 @@ pub mod enums {
|
|||
},
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum BacktraceFrom {
|
||||
#[error("...")]
|
||||
Test {
|
||||
#[from]
|
||||
source: Inner,
|
||||
#[backtrace]
|
||||
backtrace: Backtrace,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum OptBacktraceFrom {
|
||||
#[error("...")]
|
||||
Test {
|
||||
#[from]
|
||||
source: Inner,
|
||||
#[backtrace]
|
||||
backtrace: Option<Backtrace>,
|
||||
},
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_backtrace() {
|
||||
let error = PlainBacktrace::Test {
|
||||
|
@ -119,6 +173,12 @@ pub mod enums {
|
|||
backtrace: Arc::new(Backtrace::capture()),
|
||||
};
|
||||
assert!(error.backtrace().is_some());
|
||||
|
||||
let error = BacktraceFrom::from(Inner);
|
||||
assert!(error.backtrace().is_some());
|
||||
|
||||
let error = OptBacktraceFrom::from(Inner);
|
||||
assert!(error.backtrace().is_some());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue