From fe4255d765d24b3a62094a02d35077a1022887bb Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 26 Sep 2023 19:46:15 +0200 Subject: test: make unit tests not return Result --- macros/src/declare_interface_args.rs | 14 +++------ macros/src/factory/declare_default_args.rs | 23 ++++++-------- macros/src/factory/macro_args.rs | 8 ++--- macros/src/factory/type_alias.rs | 8 ++--- macros/src/fn_trait.rs | 9 ++---- macros/src/injectable/implementation.rs | 49 +++++++++++++++--------------- macros/src/injectable/macro_args.rs | 42 +++++++++---------------- 7 files changed, 59 insertions(+), 94 deletions(-) (limited to 'macros/src') diff --git a/macros/src/declare_interface_args.rs b/macros/src/declare_interface_args.rs index fea6c7b..6556153 100644 --- a/macros/src/declare_interface_args.rs +++ b/macros/src/declare_interface_args.rs @@ -60,8 +60,6 @@ impl Parse for DeclareInterfaceArgs #[cfg(test)] mod tests { - use std::error::Error; - use proc_macro2::Span; use quote::{format_ident, quote}; use syn::{parse2, Lit, LitBool}; @@ -71,13 +69,13 @@ mod tests use crate::test_utils; #[test] - fn can_parse_with_no_flags() -> Result<(), Box> + fn can_parse_with_no_flags() { let input_args = quote! { Foo -> IFoo }; - let decl_interface_args = parse2::(input_args)?; + let decl_interface_args = parse2::(input_args).unwrap(); assert_eq!( decl_interface_args.implementation, @@ -102,18 +100,16 @@ mod tests ); assert!(decl_interface_args.flags.is_empty()); - - Ok(()) } #[test] - fn can_parse_with_flags() -> Result<(), Box> + fn can_parse_with_flags() { let input_args = quote! { Foobar -> IFoobar, threadsafe_sharable = true }; - let decl_interface_args = parse2::(input_args)?; + let decl_interface_args = parse2::(input_args).unwrap(); assert_eq!( decl_interface_args.implementation, @@ -147,8 +143,6 @@ mod tests ))) }]) ); - - Ok(()) } #[test] diff --git a/macros/src/factory/declare_default_args.rs b/macros/src/factory/declare_default_args.rs index f93d29d..9930f4f 100644 --- a/macros/src/factory/declare_default_args.rs +++ b/macros/src/factory/declare_default_args.rs @@ -57,8 +57,6 @@ impl Parse for DeclareDefaultFactoryMacroArgs #[cfg(test)] mod tests { - use std::error::Error; - use proc_macro2::Span; use quote::{format_ident, quote}; use syn::token::Dyn; @@ -80,13 +78,14 @@ mod tests use crate::macro_flag::MacroFlagValue; #[test] - fn can_parse_with_interface_only() -> Result<(), Box> + fn can_parse_with_interface_only() { let input_args = quote! { dyn IFoo }; - let dec_def_fac_args = parse2::(input_args)?; + let dec_def_fac_args = + parse2::(input_args).unwrap(); assert_eq!( dec_def_fac_args.interface, @@ -108,18 +107,17 @@ mod tests ); assert!(dec_def_fac_args.flags.is_empty()); - - Ok(()) } #[test] - fn can_parse_with_interface_and_single_flag() -> Result<(), Box> + fn can_parse_with_interface_and_single_flag() { let input_args = quote! { dyn IBar, threadsafe = true }; - let dec_def_fac_args = parse2::(input_args)?; + let dec_def_fac_args = + parse2::(input_args).unwrap(); assert_eq!( dec_def_fac_args.interface, @@ -150,18 +148,17 @@ mod tests ))) }]) ); - - Ok(()) } #[test] - fn can_parse_with_interface_and_multiple_flags() -> Result<(), Box> + fn can_parse_with_interface_and_multiple_flags() { let input_args = quote! { dyn IBar, threadsafe = true, async = false }; - let dec_def_fac_args = parse2::(input_args)?; + let dec_def_fac_args = + parse2::(input_args).unwrap(); assert_eq!( dec_def_fac_args.interface, @@ -201,8 +198,6 @@ mod tests } ]) ); - - Ok(()) } #[test] diff --git a/macros/src/factory/macro_args.rs b/macros/src/factory/macro_args.rs index 76b29a2..676b412 100644 --- a/macros/src/factory/macro_args.rs +++ b/macros/src/factory/macro_args.rs @@ -46,8 +46,6 @@ impl Parse for FactoryMacroArgs #[cfg(test)] mod tests { - use std::error::Error; - use proc_macro2::Span; use quote::{format_ident, quote}; use syn::{parse2, Lit, LitBool}; @@ -56,13 +54,13 @@ mod tests use crate::macro_flag::MacroFlagValue; #[test] - fn can_parse_with_single_flag() -> Result<(), Box> + fn can_parse_with_single_flag() { let input_args = quote! { threadsafe = true }; - let factory_macro_args = parse2::(input_args)?; + let factory_macro_args = parse2::(input_args).unwrap(); assert_eq!( factory_macro_args.flags, @@ -74,8 +72,6 @@ mod tests ))) }]) ); - - Ok(()) } #[test] diff --git a/macros/src/factory/type_alias.rs b/macros/src/factory/type_alias.rs index fafcd54..cfa254f 100644 --- a/macros/src/factory/type_alias.rs +++ b/macros/src/factory/type_alias.rs @@ -31,8 +31,6 @@ impl Parse for FactoryTypeAlias #[cfg(test)] mod tests { - use std::error::Error; - use quote::{format_ident, quote}; use syn::punctuated::Punctuated; use syn::token::And; @@ -42,13 +40,13 @@ mod tests use crate::test_utils; #[test] - fn can_parse() -> Result<(), Box> + fn can_parse() { let input_args = quote! { type FooFactory = dyn Fn(String, &u32) -> Foo; }; - let factory_type_alias = parse2::(input_args)?; + let factory_type_alias = parse2::(input_args).unwrap(); assert_eq!( factory_type_alias.factory_interface.inputs, @@ -66,7 +64,5 @@ mod tests }) ]) ); - - Ok(()) } } diff --git a/macros/src/fn_trait.rs b/macros/src/fn_trait.rs index 31d7d95..0858cca 100644 --- a/macros/src/fn_trait.rs +++ b/macros/src/fn_trait.rs @@ -88,8 +88,6 @@ impl ToTokens for FnTrait #[cfg(test)] mod tests { - use std::error::Error; - use quote::{format_ident, quote}; use syn::token::{Dyn, RArrow}; use syn::{parse2, PathSegment}; @@ -98,12 +96,13 @@ mod tests use crate::test_utils; #[test] - fn can_parse_fn_trait() -> Result<(), Box> + fn can_parse_fn_trait() { assert_eq!( parse2::(quote! { dyn Fn(String, u32) -> Handle - })?, + }) + .unwrap(), FnTrait { dyn_token: Dyn::default(), trait_ident: format_ident!("Fn"), @@ -128,8 +127,6 @@ mod tests Fn(u32) -> Handle }) .is_err()); - - Ok(()) } #[test] 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> + fn can_create_single_get_dep_method_call() { let mut mock_dependency = MockIDependency::new(); @@ -893,10 +893,11 @@ mod tests InjectableImpl::::create_single_get_dep_method_call( &mock_dependency, false, - )?; + ) + .unwrap(); assert_eq!( - parse2::(output)?, + parse2::(output).unwrap(), parse2::(quote! { #di_container_var_ident .get_bound::( @@ -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> + fn can_create_single_get_dep_method_call_with_name() { let mut mock_dependency = MockIDependency::new(); @@ -944,10 +944,11 @@ mod tests InjectableImpl::::create_single_get_dep_method_call( &mock_dependency, false, - )?; + ) + .unwrap(); assert_eq!( - parse2::(output)?, + parse2::(output).unwrap(), parse2::(quote! { #di_container_var_ident .get_bound::( @@ -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> + fn can_create_single_get_dep_method_call_async() { let mut mock_dependency = MockIDependency::new(); @@ -993,10 +993,11 @@ mod tests InjectableImpl::::create_single_get_dep_method_call( &mock_dependency, true, - )?; + ) + .unwrap(); assert_eq!( - parse2::(output)?, + parse2::(output).unwrap(), parse2::(quote! { #di_container_var_ident .get_bound::( @@ -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> + fn can_create_single_get_dep_method_call_async_with_name() { let mut mock_dependency = MockIDependency::new(); @@ -1046,10 +1045,11 @@ mod tests InjectableImpl::::create_single_get_dep_method_call( &mock_dependency, true, - )?; + ) + .unwrap(); assert_eq!( - parse2::(output)?, + parse2::(output).unwrap(), parse2::(quote! { #di_container_var_ident .get_bound::( @@ -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> + fn can_parse_with_only_interface() { let input_args = quote! { IFoo }; - let injectable_macro_args = parse2::(input_args)?; + let injectable_macro_args = parse2::(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> + fn can_parse_with_nothing() { let input_args = quote! {}; - let injectable_macro_args = parse2::(input_args)?; + let injectable_macro_args = parse2::(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> + fn can_parse_with_interface_and_flags() { let input_args = quote! { IFoo, no_doc_hidden = true, async = false }; - let injectable_macro_args = parse2::(input_args)?; + let injectable_macro_args = parse2::(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> + fn can_parse_with_flags_only() { let input_args = quote! { async = false, no_declare_concrete_interface = false }; - let injectable_macro_args = parse2::(input_args)?; + let injectable_macro_args = parse2::(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> + fn check_flags_fail_with_unknown_flag() { let input_args = quote! { IFoo, haha = true, async = false }; - let injectable_macro_args = parse2::(input_args)?; + let injectable_macro_args = parse2::(input_args).unwrap(); assert!(injectable_macro_args.check_flags().is_err()); - - Ok(()) } #[test] - fn check_flags_fail_with_duplicate_flag() -> Result<(), Box> + fn check_flags_fail_with_duplicate_flag() { let macro_args = parse2::(quote! { IFoo, async = false, no_doc_hidden = true, async = false - })?; + }) + .unwrap(); assert!(macro_args.check_flags().is_err()); let macro_args_two = parse2::(quote! { IFoo, async = true , no_doc_hidden = true, async = false - })?; + }) + .unwrap(); assert!(macro_args_two.check_flags().is_err()); - - Ok(()) } } -- cgit v1.2.3-18-g5258