Skip to content

Commit

Permalink
Update backtrace test to provider API
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Aug 31, 2022
1 parent 986e106 commit e11c97b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
41 changes: 22 additions & 19 deletions tests/test_backtrace.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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());
}
}

Expand Down
5 changes: 4 additions & 1 deletion tests/test_option.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down

0 comments on commit e11c97b

Please sign in to comment.