#![cfg_attr(
feature = "unstable-error-generic-member-access",
feature(error_generic_member_access)
)]
#![allow(
clippy::allow_attributes,
reason = "unused_parens is version-dependent, so expect would be unfulfilled on the MSRV"
)]
#![allow(
unused_parens,
reason = "parenthesized trait object is the regression under test"
)]
use oopsie::{Contextual as _, Oopsie};
use std::error::Error as StdError;
#[derive(Debug, Oopsie)]
#[oopsie(module(false))]
enum Wrapper {
#[oopsie("concrete source")]
Concrete { source: std::io::Error },
#[oopsie("boxed concrete source")]
BoxedConcrete { source: Box<std::io::Error> },
#[oopsie("boxed dyn source")]
BoxedDyn {
source: Box<dyn StdError + Send + Sync + 'static>,
},
}
#[test]
fn concrete_source_chain_intact() {
let inner = std::io::Error::other("disk full");
let e: Wrapper = Concrete.build_error(inner);
let s = StdError::source(&e).expect("source missing");
assert_eq!(s.to_string(), "disk full");
}
#[test]
fn boxed_concrete_source_chain_intact() {
let inner = std::io::Error::other("disk full");
let e: Wrapper = BoxedConcrete.build_error(inner);
let s = StdError::source(&e).expect("source missing");
assert_eq!(s.to_string(), "disk full");
}
#[test]
fn boxed_dyn_source_chain_intact() {
let inner: Box<dyn StdError + Send + Sync + 'static> =
Box::new(std::io::Error::other("disk full"));
let e: Wrapper = BoxedDyn.build_error(inner);
let s = StdError::source(&e).expect("source missing");
assert_eq!(s.to_string(), "disk full");
}
#[derive(Debug, Oopsie)]
#[oopsie("struct-shaped boxed dyn source")]
pub struct StructBoxedDyn {
source: Box<dyn StdError + Send + Sync + 'static>,
}
#[test]
fn struct_boxed_dyn_source_chain_intact() {
let inner: Box<dyn StdError + Send + Sync + 'static> =
Box::new(std::io::Error::other("disk full"));
let e = StructBoxedDyn { source: inner };
let s = StdError::source(&e).expect("source missing");
assert_eq!(s.to_string(), "disk full");
}
#[derive(Debug, Oopsie)]
#[oopsie("struct-shaped parenthesized boxed dyn source")]
pub struct StructParenBoxedDyn {
source: Box<(dyn StdError + Send + Sync + 'static)>,
}
#[test]
fn struct_paren_boxed_dyn_source_chain_intact() {
let inner: Box<(dyn StdError + Send + Sync + 'static)> =
Box::new(std::io::Error::other("disk full"));
let e = StructParenBoxedDyn { source: inner };
let s = StdError::source(&e).expect("source missing");
assert_eq!(s.to_string(), "disk full");
}