From b087000b7ebb725d617be38c251ebc8e2bfea1a5 Mon Sep 17 00:00:00 2001 From: Brooks J Rady Date: Thu, 25 Apr 2024 15:34:13 -0700 Subject: [PATCH] test(boxed): add failing test for bug #369 --- tests/test_boxed.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/test_boxed.rs b/tests/test_boxed.rs index fcf273d..9f9f4e2 100644 --- a/tests/test_boxed.rs +++ b/tests/test_boxed.rs @@ -1,6 +1,7 @@ use miette::{miette, Diagnostic, LabeledSpan, Report, SourceSpan}; use std::error::Error as StdError; use std::io; +use std::ops::Deref; use thiserror::Error; #[derive(Error, Debug)] @@ -159,7 +160,7 @@ impl Diagnostic for CustomDiagnostic { #[test] fn test_boxed_custom_diagnostic() { - fn assert_report(report: &Report) { + fn assert_report(report: &impl Deref) { assert_eq!( report.source().map(|source| source.to_string()), Some("oh no!".to_owned()), @@ -215,6 +216,13 @@ fn test_boxed_custom_diagnostic() { let main_diagnostic = Box::new(main_diagnostic) as Box; let report = miette!(main_diagnostic); assert_report(&report); + + // Now make sure that conversion to a trait-object is lossless! + let report_ref: &dyn Diagnostic = report.as_ref(); + assert_report(&report_ref); + + let report_box: Box = report.into(); + assert_report(&report_box); } #[test]