From 8ba24da443d7cb7d9b490e9be9253136361f3368 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=BCller?= Date: Fri, 6 May 2022 07:59:48 +0200 Subject: [PATCH] Add more tests for diagnostic_source --- tests/test_diagnostic_source_macro.rs | 45 +++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/tests/test_diagnostic_source_macro.rs b/tests/test_diagnostic_source_macro.rs index d7c5d2d..8af2e88 100644 --- a/tests/test_diagnostic_source_macro.rs +++ b/tests/test_diagnostic_source_macro.rs @@ -6,15 +6,56 @@ struct AnErr; #[derive(Debug, miette::Diagnostic, thiserror::Error)] #[error("TestError")] -struct TestError { +struct TestStructError { #[diagnostic_source] asdf_inner_foo: AnErr, } +#[derive(Debug, miette::Diagnostic, thiserror::Error)] +#[error("TestError")] +enum TestEnumError { + Without, + WithTuple(#[diagnostic_source] AnErr), + WithStruct { + #[diagnostic_source] + inner: AnErr, + }, +} + +#[derive(Debug, miette::Diagnostic, thiserror::Error)] +#[error("TestError")] +struct TestTupleError(#[diagnostic_source] AnErr); + +#[derive(Debug, miette::Diagnostic, thiserror::Error)] +#[error("TestError")] +struct TestBoxedError(#[diagnostic_source] Box); + +#[derive(Debug, miette::Diagnostic, thiserror::Error)] +#[error("TestError")] +struct TestArcedError(#[diagnostic_source] std::sync::Arc); + #[test] fn test_diagnostic_source() { - let error = TestError { + let error = TestStructError { asdf_inner_foo: AnErr, }; assert!(error.diagnostic_source().is_some()); + + let error = TestEnumError::Without; + assert!(error.diagnostic_source().is_none()); + + let error = TestEnumError::WithTuple(AnErr); + assert!(error.diagnostic_source().is_some()); + + let error = TestEnumError::WithStruct { inner: AnErr }; + assert!(error.diagnostic_source().is_some()); + + let error = TestTupleError(AnErr); + assert!(error.diagnostic_source().is_some()); + + let error = TestBoxedError(Box::new(AnErr)); + assert!(error.diagnostic_source().is_some()); + + let error = TestArcedError(std::sync::Arc::new(AnErr)); + assert!(error.diagnostic_source().is_some()); }