diff options
author | HampusM <hampus@hampusmat.com> | 2023-09-26 19:46:15 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-09-26 19:46:15 +0200 |
commit | fe4255d765d24b3a62094a02d35077a1022887bb (patch) | |
tree | ee47f81339f569ec3b42d56778c9be514cb80ae4 /macros/src/injectable | |
parent | 267ab1dc45c7e2cb68d8238c04376a258dcf61c9 (diff) |
test: make unit tests not return Result
Diffstat (limited to 'macros/src/injectable')
-rw-r--r-- | macros/src/injectable/implementation.rs | 49 | ||||
-rw-r--r-- | macros/src/injectable/macro_args.rs | 42 |
2 files changed, 39 insertions, 52 deletions
diff --git a/macros/src/injectable/implementation.rs b/macros/src/injectable/implementation.rs index b3e57c2..74a907e 100644 --- a/macros/src/injectable/implementation.rs +++ b/macros/src/injectable/implementation.rs @@ -870,7 +870,7 @@ mod tests } #[test] - fn can_create_single_get_dep_method_call() -> Result<(), Box<dyn Error>> + fn can_create_single_get_dep_method_call() { let mut mock_dependency = MockIDependency::new(); @@ -893,10 +893,11 @@ mod tests InjectableImpl::<MockIDependency>::create_single_get_dep_method_call( &mock_dependency, false, - )?; + ) + .unwrap(); assert_eq!( - parse2::<Expr>(output)?, + parse2::<Expr>(output).unwrap(), parse2::<Expr>(quote! { #di_container_var_ident .get_bound::<Foo>( @@ -912,14 +913,13 @@ mod tests reason: err, dependency_name: "Foo" })? - })? + }) + .unwrap() ); - - Ok(()) } #[test] - fn can_create_single_get_dep_method_call_with_name() -> Result<(), Box<dyn Error>> + fn can_create_single_get_dep_method_call_with_name() { let mut mock_dependency = MockIDependency::new(); @@ -944,10 +944,11 @@ mod tests InjectableImpl::<MockIDependency>::create_single_get_dep_method_call( &mock_dependency, false, - )?; + ) + .unwrap(); assert_eq!( - parse2::<Expr>(output)?, + parse2::<Expr>(output).unwrap(), parse2::<Expr>(quote! { #di_container_var_ident .get_bound::<Foo>( @@ -963,14 +964,13 @@ mod tests reason: err, dependency_name: "Foo" })? - })? + }) + .unwrap() ); - - Ok(()) } #[test] - fn can_create_single_get_dep_method_call_async() -> Result<(), Box<dyn Error>> + fn can_create_single_get_dep_method_call_async() { let mut mock_dependency = MockIDependency::new(); @@ -993,10 +993,11 @@ mod tests InjectableImpl::<MockIDependency>::create_single_get_dep_method_call( &mock_dependency, true, - )?; + ) + .unwrap(); assert_eq!( - parse2::<Expr>(output)?, + parse2::<Expr>(output).unwrap(), parse2::<Expr>(quote! { #di_container_var_ident .get_bound::<Foo>( @@ -1013,15 +1014,13 @@ mod tests reason: err, dependency_name: "Foo" })? - })? + }) + .unwrap() ); - - Ok(()) } #[test] - fn can_create_single_get_dep_method_call_async_with_name( - ) -> Result<(), Box<dyn Error>> + fn can_create_single_get_dep_method_call_async_with_name() { let mut mock_dependency = MockIDependency::new(); @@ -1046,10 +1045,11 @@ mod tests InjectableImpl::<MockIDependency>::create_single_get_dep_method_call( &mock_dependency, true, - )?; + ) + .unwrap(); assert_eq!( - parse2::<Expr>(output)?, + parse2::<Expr>(output).unwrap(), parse2::<Expr>(quote! { #di_container_var_ident .get_bound::<Foo>( @@ -1066,9 +1066,8 @@ mod tests reason: err, dependency_name: "Foo" })? - })? + }) + .unwrap() ); - - Ok(()) } } diff --git a/macros/src/injectable/macro_args.rs b/macros/src/injectable/macro_args.rs index ee398fc..719d551 100644 --- a/macros/src/injectable/macro_args.rs +++ b/macros/src/injectable/macro_args.rs @@ -111,8 +111,6 @@ pub enum InjectableMacroArgsError #[cfg(test)] mod tests { - use std::error::Error; - use proc_macro2::Span; use quote::{format_ident, quote}; use syn::{parse2, Lit, LitBool}; @@ -122,13 +120,13 @@ mod tests use crate::test_utils; #[test] - fn can_parse_with_only_interface() -> Result<(), Box<dyn Error>> + fn can_parse_with_only_interface() { let input_args = quote! { IFoo }; - let injectable_macro_args = parse2::<InjectableMacroArgs>(input_args)?; + let injectable_macro_args = parse2::<InjectableMacroArgs>(input_args).unwrap(); assert!(matches!(injectable_macro_args.interface, Some(interface) if interface == TypePath { @@ -140,31 +138,27 @@ mod tests )); assert!(injectable_macro_args.flags.is_empty()); - - Ok(()) } #[test] - fn can_parse_with_nothing() -> Result<(), Box<dyn Error>> + fn can_parse_with_nothing() { let input_args = quote! {}; - let injectable_macro_args = parse2::<InjectableMacroArgs>(input_args)?; + let injectable_macro_args = parse2::<InjectableMacroArgs>(input_args).unwrap(); assert!(injectable_macro_args.interface.is_none()); assert!(injectable_macro_args.flags.is_empty()); - - Ok(()) } #[test] - fn can_parse_with_interface_and_flags() -> Result<(), Box<dyn Error>> + fn can_parse_with_interface_and_flags() { let input_args = quote! { IFoo, no_doc_hidden = true, async = false }; - let injectable_macro_args = parse2::<InjectableMacroArgs>(input_args)?; + let injectable_macro_args = parse2::<InjectableMacroArgs>(input_args).unwrap(); assert!(matches!(injectable_macro_args.interface, Some(interface) if interface == TypePath { @@ -194,18 +188,16 @@ mod tests } ]) ); - - Ok(()) } #[test] - fn can_parse_with_flags_only() -> Result<(), Box<dyn Error>> + fn can_parse_with_flags_only() { let input_args = quote! { async = false, no_declare_concrete_interface = false }; - let injectable_macro_args = parse2::<InjectableMacroArgs>(input_args)?; + let injectable_macro_args = parse2::<InjectableMacroArgs>(input_args).unwrap(); assert!(injectable_macro_args.interface.is_none()); @@ -228,8 +220,6 @@ mod tests } ]) ); - - Ok(()) } #[test] @@ -257,34 +247,32 @@ mod tests } #[test] - fn check_flags_fail_with_unknown_flag() -> Result<(), Box<dyn Error>> + fn check_flags_fail_with_unknown_flag() { let input_args = quote! { IFoo, haha = true, async = false }; - let injectable_macro_args = parse2::<InjectableMacroArgs>(input_args)?; + let injectable_macro_args = parse2::<InjectableMacroArgs>(input_args).unwrap(); assert!(injectable_macro_args.check_flags().is_err()); - - Ok(()) } #[test] - fn check_flags_fail_with_duplicate_flag() -> Result<(), Box<dyn Error>> + fn check_flags_fail_with_duplicate_flag() { let macro_args = parse2::<InjectableMacroArgs>(quote! { IFoo, async = false, no_doc_hidden = true, async = false - })?; + }) + .unwrap(); assert!(macro_args.check_flags().is_err()); let macro_args_two = parse2::<InjectableMacroArgs>(quote! { IFoo, async = true , no_doc_hidden = true, async = false - })?; + }) + .unwrap(); assert!(macro_args_two.check_flags().is_err()); - - Ok(()) } } |