From 1698551cddb26769c1b91c71ab2892954caf23a8 Mon Sep 17 00:00:00 2001 From: Brooks J Rady Date: Tue, 26 Mar 2024 14:46:31 -0700 Subject: [PATCH] tests(graphical): reproduce poor nested wrapping --- tests/graphical.rs | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/tests/graphical.rs b/tests/graphical.rs index 4763117..b2a5f93 100644 --- a/tests/graphical.rs +++ b/tests/graphical.rs @@ -264,6 +264,58 @@ fn wrap_option() -> Result<(), MietteError> { Ok(()) } +#[test] +fn wrapping_nested_errors() -> Result<(), MietteError> { + #[derive(Debug, Diagnostic, Error)] + #[error("This is the parent error, the error with the children, kiddos, pups, as it were, and so on...")] + #[diagnostic( + code(mama::error), + help( + "try doing it better next time? I mean, you could have also done better this time, but no?" + ) + )] + struct MamaError { + #[diagnostic_source] + baby: BabyError, + } + + #[derive(Debug, Diagnostic, Error)] + #[error("Wah wah: I may be small, but I'll cause a proper bout of trouble — just try wrapping this mess of a line, buddo!")] + #[diagnostic( + code(baby::error), + help( + "it cannot be helped... would youuuu really want to get rid of an error that's so cute?" + ) + )] + struct BabyError; + + let err = MamaError { baby: BabyError }; + let out = fmt_report_with_settings(err.into(), |handler| handler.with_width(50)); + let expected = r#"mama::error + + × This is the parent error, the error with + │ the children, kiddos, pups, as it were, and + │ so on... + ╰─▶ baby::error + + × Wah wah: I may be small, but I'll + cause a + │ proper bout of trouble — just try + wrapping + │ this mess of a line, buddo! + help: it cannot be helped... would + youuuu + really want to get rid of an error + that's so cute? + + help: try doing it better next time? I mean, + you could have also done better this + time, but no? +"#; + assert_eq!(expected, out); + Ok(()) +} + #[test] fn empty_source() -> Result<(), MietteError> { #[derive(Debug, Diagnostic, Error)]