#![cfg(nightly)] #![cfg_attr(nightly, feature(error_generic_member_access))] mod common; #[allow(clippy::wildcard_imports)] use common::*; use error_stack::Report; #[test] fn request_attachment() { let report = create_report(); assert_eq!(report.request_ref::().count(), 0); let report = report.attach(AttachmentA(10)).attach(AttachmentB(20)); let request_a = report.request_ref::().collect::>(); assert_eq!(request_a.len(), 1); assert_eq!(request_a[0].0, 10); let request_b = report.request_ref::().collect::>(); assert_eq!(request_b.len(), 1); assert_eq!(request_b[0].0, 20); } #[test] fn request_context() { let report = create_report(); assert_eq!(report.request_ref::().count(), 0); assert_eq!(report.request_value::().count(), 0); let report = report.change_context(ContextA(10)); assert_eq!(report.request_ref::().count(), 0); assert_eq!(report.request_value::().count(), 0); assert_eq!(report.request_ref::().count(), 0); assert_eq!(report.request_value::().count(), 0); let request_a = report.request_ref::().collect::>(); assert_eq!(request_a.len(), 1); assert_eq!(*request_a[0], 10); let request_b = report.request_value::().collect::>(); assert_eq!(request_b.len(), 1); assert_eq!(request_b[0], 10); } #[test] fn context_provision() { let report = Report::from(ContextA(10)); assert_eq!(report.request_ref::().count(), 1); }