From 1c53b5749b5eb8cda115e84272c011aca54598c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=BCller?= Date: Thu, 18 May 2023 16:20:54 +0200 Subject: [PATCH] Add test for diagnostic_source printing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcel Müller --- tests/test_diagnostic_source_macro.rs | 38 +++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/tests/test_diagnostic_source_macro.rs b/tests/test_diagnostic_source_macro.rs index 0e3770f..327b6c2 100644 --- a/tests/test_diagnostic_source_macro.rs +++ b/tests/test_diagnostic_source_macro.rs @@ -19,7 +19,7 @@ struct AnErr; #[error("TestError")] struct TestStructError { #[diagnostic_source] - asdf_inner_foo: AnErr, + asdf_inner_foo: SourceError, } #[derive(Debug, miette::Diagnostic, thiserror::Error)] @@ -48,7 +48,11 @@ struct TestArcedError(#[diagnostic_source] std::sync::Arc); #[test] fn test_diagnostic_source() { let error = TestStructError { - asdf_inner_foo: AnErr, + asdf_inner_foo: SourceError { + code: String::new(), + help: String::new(), + label: (0, 0), + }, }; assert!(error.diagnostic_source().is_some()); @@ -101,3 +105,33 @@ fn test_diagnostic_source_pass_extra_info() { .to_string(); assert_eq!(expected, out); } + +#[test] +fn test_diagnostic_source_is_output() { + let diag = TestStructError { + asdf_inner_foo: SourceError { + code: String::from("right here"), + help: String::from("That's where the error is!"), + label: (6, 4), + }, + }; + let mut out = String::new(); + miette::GraphicalReportHandler::new_themed(miette::GraphicalTheme::unicode_nocolor()) + .with_width(80) + .render_report(&mut out, &diag) + .unwrap(); + println!("{}", out); + + let expected = r#" × TestError + ╰─▶ × A complex error happened + ╭──── + 1 │ right here + · ──┬─ + · ╰── here + ╰──── + help: That's where the error is! + +"#; + + assert_eq!(expected, out); +}