#![allow(dead_code)] // some code is tested for type checking only use super::*; #[test] fn named_implicit_no_source() { derive_display!(TestErr, T); #[derive(Default, Debug, Error)] struct TestErr { field: T, } assert!(TestErr::::default().source().is_none()); } #[test] fn named_implicit_source() { derive_display!(TestErr, E, T); #[derive(Default, Debug, Error)] struct TestErr { source: E, field: T, } let err = TestErr::::default(); assert!(err.source().is_some()); assert!(err.source().unwrap().is::()); } #[test] fn named_explicit_no_source() { derive_display!(TestErr, E, T); #[derive(Default, Debug, Error)] struct TestErr { #[error(not(source))] source: E, field: T, } let err = TestErr::::default(); assert!(err.source().is_none()); } #[test] fn named_explicit_source() { derive_display!(TestErr, E, T); #[derive(Default, Debug, Error)] struct TestErr { #[error(source)] explicit_source: E, field: T, } let err = TestErr::::default(); assert!(err.source().is_some()); assert!(err.source().unwrap().is::()); } #[test] fn named_explicit_no_source_redundant() { derive_display!(TestErr, T); #[derive(Default, Debug, Error)] struct TestErr { #[error(not(source))] field: T, } assert!(TestErr::::default().source().is_none()); } #[test] fn named_explicit_source_redundant() { derive_display!(TestErr, E, T); #[derive(Default, Debug, Error)] struct TestErr { #[error(source)] source: E, field: T, } let err = TestErr::::default(); assert!(err.source().is_some()); assert!(err.source().unwrap().is::()); } #[test] fn named_explicit_suppresses_implicit() { derive_display!(TestErr, E, T); #[derive(Default, Debug, Error)] struct TestErr { source: E, #[error(source)] field: T, } let err = TestErr::::default(); assert!(err.source().is_some()); assert!(err.source().unwrap().is::()); } #[test] fn unnamed_implicit_no_source() { derive_display!(TestErr, T); #[derive(Default, Debug, Error)] struct TestErr(T, T); assert!(TestErr::::default().source().is_none()); } #[test] fn unnamed_implicit_source() { derive_display!(TestErr, E); #[derive(Default, Debug, Error)] struct TestErr(E); let err = TestErr::::default(); assert!(err.source().is_some()); assert!(err.source().unwrap().is::()); } #[test] fn unnamed_explicit_no_source() { derive_display!(TestErr, E); #[derive(Default, Debug, Error)] struct TestErr(#[error(not(source))] E); assert!(TestErr::::default().source().is_none()); } #[test] fn unnamed_explicit_source() { derive_display!(TestErr, E, T); #[derive(Default, Debug, Error)] struct TestErr(#[error(source)] E, T); let err = TestErr::::default(); assert!(err.source().is_some()); assert!(err.source().unwrap().is::()); } #[test] fn unnamed_explicit_no_source_redundant() { derive_display!(TestErr, T); #[derive(Default, Debug, Error)] struct TestErr(#[error(not(source))] T, #[error(not(source))] T); assert!(TestErr::::default().source().is_none()); } #[test] fn unnamed_explicit_source_redundant() { derive_display!(TestErr, E); #[derive(Default, Debug, Error)] struct TestErr(#[error(source)] E); let err = TestErr::::default(); assert!(err.source().is_some()); assert!(err.source().unwrap().is::()); } #[test] fn named_ignore() { derive_display!(TestErr, E, T); #[derive(Default, Debug, Error)] struct TestErr { #[error(ignore)] source: E, field: T, } assert!(TestErr::::default().source().is_none()); } #[test] fn unnamed_ignore() { derive_display!(TestErr, E); #[derive(Default, Debug, Error)] struct TestErr(#[error(ignore)] E); assert!(TestErr::::default().source().is_none()); } #[test] fn named_ignore_redundant() { derive_display!(TestErr, T); #[derive(Default, Debug, Error)] struct TestErr { #[error(ignore)] field: T, } assert!(TestErr::::default().source().is_none()); } #[test] fn unnamed_ignore_redundant() { derive_display!(TestErr, T); #[derive(Default, Debug, Error)] struct TestErr(#[error(ignore)] T, #[error(ignore)] T); assert!(TestErr::::default().source().is_none()); } #[test] fn named_struct_ignore() { derive_display!(TestErr, E, T); #[derive(Default, Debug, Error)] #[error(ignore)] struct TestErr { source: E, field: T, } assert!(TestErr::::default().source().is_none()) } #[test] fn unnamed_struct_ignore() { derive_display!(TestErr, E); #[derive(Default, Debug, Error)] #[error(ignore)] struct TestErr(E); assert!(TestErr::::default().source().is_none()) } #[test] fn named_struct_ignore_redundant() { derive_display!(TestErr, T); #[derive(Default, Debug, Error)] #[error(ignore)] struct TestErr { field: T, } assert!(TestErr::::default().source().is_none()) } #[test] fn unnamed_struct_ignore_redundant() { derive_display!(TestErr, T); #[derive(Default, Debug, Error)] #[error(ignore)] struct TestErr(T, T); assert!(TestErr::::default().source().is_none()) }