Update backtrace test to provider API

This commit is contained in:
David Tolnay 2022-08-30 19:04:56 -07:00
parent 986e106172
commit e11c97babf
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82
2 changed files with 26 additions and 20 deletions

View file

@ -1,4 +1,7 @@
#![cfg_attr(thiserror_nightly_testing, feature(backtrace))]
#![cfg_attr(
thiserror_nightly_testing,
feature(error_generic_member_access, provide_any)
)]
use thiserror::Error;
@ -16,8 +19,8 @@ pub struct InnerBacktrace {
#[cfg(thiserror_nightly_testing)]
pub mod structs {
use super::{Inner, InnerBacktrace};
use std::any;
use std::backtrace::Backtrace;
use std::error::Error;
use std::sync::Arc;
use thiserror::Error;
@ -88,44 +91,44 @@ pub mod structs {
let error = PlainBacktrace {
backtrace: Backtrace::capture(),
};
assert!(error.backtrace().is_some());
assert!(any::request_ref::<Backtrace>(&error).is_some());
let error = ExplicitBacktrace {
backtrace: Backtrace::capture(),
};
assert!(error.backtrace().is_some());
assert!(any::request_ref::<Backtrace>(&error).is_some());
let error = OptBacktrace {
backtrace: Some(Backtrace::capture()),
};
assert!(error.backtrace().is_some());
assert!(any::request_ref::<Backtrace>(&error).is_some());
let error = ArcBacktrace {
backtrace: Arc::new(Backtrace::capture()),
};
assert!(error.backtrace().is_some());
assert!(any::request_ref::<Backtrace>(&error).is_some());
let error = BacktraceFrom::from(Inner);
assert!(error.backtrace().is_some());
assert!(any::request_ref::<Backtrace>(&error).is_some());
let error = CombinedBacktraceFrom::from(InnerBacktrace {
backtrace: Backtrace::capture(),
});
assert!(error.backtrace().is_some());
assert!(any::request_ref::<Backtrace>(&error).is_some());
let error = OptBacktraceFrom::from(Inner);
assert!(error.backtrace().is_some());
assert!(any::request_ref::<Backtrace>(&error).is_some());
let error = ArcBacktraceFrom::from(Inner);
assert!(error.backtrace().is_some());
assert!(any::request_ref::<Backtrace>(&error).is_some());
}
}
#[cfg(thiserror_nightly_testing)]
pub mod enums {
use super::{Inner, InnerBacktrace};
use std::any;
use std::backtrace::Backtrace;
use std::error::Error;
use std::sync::Arc;
use thiserror::Error;
@ -210,36 +213,36 @@ pub mod enums {
let error = PlainBacktrace::Test {
backtrace: Backtrace::capture(),
};
assert!(error.backtrace().is_some());
assert!(any::request_ref::<Backtrace>(&error).is_some());
let error = ExplicitBacktrace::Test {
backtrace: Backtrace::capture(),
};
assert!(error.backtrace().is_some());
assert!(any::request_ref::<Backtrace>(&error).is_some());
let error = OptBacktrace::Test {
backtrace: Some(Backtrace::capture()),
};
assert!(error.backtrace().is_some());
assert!(any::request_ref::<Backtrace>(&error).is_some());
let error = ArcBacktrace::Test {
backtrace: Arc::new(Backtrace::capture()),
};
assert!(error.backtrace().is_some());
assert!(any::request_ref::<Backtrace>(&error).is_some());
let error = BacktraceFrom::from(Inner);
assert!(error.backtrace().is_some());
assert!(any::request_ref::<Backtrace>(&error).is_some());
let error = CombinedBacktraceFrom::from(InnerBacktrace {
backtrace: Backtrace::capture(),
});
assert!(error.backtrace().is_some());
assert!(any::request_ref::<Backtrace>(&error).is_some());
let error = OptBacktraceFrom::from(Inner);
assert!(error.backtrace().is_some());
assert!(any::request_ref::<Backtrace>(&error).is_some());
let error = ArcBacktraceFrom::from(Inner);
assert!(error.backtrace().is_some());
assert!(any::request_ref::<Backtrace>(&error).is_some());
}
}

View file

@ -1,4 +1,7 @@
#![cfg_attr(thiserror_nightly_testing, feature(backtrace))]
#![cfg_attr(
thiserror_nightly_testing,
feature(error_generic_member_access, provide_any)
)]
#[cfg(thiserror_nightly_testing)]
pub mod structs {