diff --git a/neotest-macros/src/input/subtest_input.rs b/neotest-macros/src/input/subtest_input.rs index 4b56302..1390960 100644 --- a/neotest-macros/src/input/subtest_input.rs +++ b/neotest-macros/src/input/subtest_input.rs @@ -5,19 +5,15 @@ use syn::Token; pub struct SubtestInput { pub ident: syn::Ident, - pub stmts: Vec, + pub block: syn::Block, } impl Parse for SubtestInput { fn parse(input: ParseStream) -> syn::Result { - input.parse::()?; let ident: syn::Ident = input.parse()?; - input.parse::()?; + input.parse::()?; + let block: syn::Block = input.parse()?; - let mut stmts: Vec = Default::default(); - while !input.is_empty() { - stmts.push(input.parse()?); - } - Ok(Self { ident, stmts }) + Ok(Self { ident, block }) } } diff --git a/neotest-macros/src/lib.rs b/neotest-macros/src/lib.rs index 269ff40..01c4790 100644 --- a/neotest-macros/src/lib.rs +++ b/neotest-macros/src/lib.rs @@ -84,18 +84,18 @@ pub fn neotest_fixture(attribute: TokenStream, item: TokenStream) -> TokenStream } struct Subtest { - stmts: Vec, + block: syn::Block, } impl quote::ToTokens for Subtest { fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) { let context = common::ident::context(); - let inner = Inner(&self.stmts); + let block = &self.block; let stmt: syn::Stmt = syn::parse_quote! { if #context.can_execute_subtest() { #[allow(unused)] let mut #context = #context.subtest(); - #inner + #block }; }; stmt.to_tokens(tokens); @@ -105,7 +105,7 @@ impl quote::ToTokens for Subtest { #[proc_macro] pub fn subtest(item: TokenStream) -> TokenStream { let input = syn::parse_macro_input!(item as SubtestInput); - let subtest = Subtest { stmts: input.stmts }; + let subtest = Subtest { block: input.block }; subtest.to_token_stream().into() } diff --git a/neotest-macros/src/suite/section_graph.rs b/neotest-macros/src/suite/section_graph.rs index 78df800..ad5b316 100644 --- a/neotest-macros/src/suite/section_graph.rs +++ b/neotest-macros/src/suite/section_graph.rs @@ -127,7 +127,7 @@ fn examine_macro(sections: &mut Vec
, mac: &Macro, fail_on_macro: bool) let input: SubtestInput = syn::parse(tokens)?; define_subsection(sections, input.ident, |sections| -> syn::Result<()> { - examine_stmts(sections, &input.stmts, fail_on_macro) + examine_stmts(sections, &input.block.stmts, fail_on_macro) })?; } Ok(()) diff --git a/neotest/examples/subtest.rs b/neotest/examples/subtest.rs index 5418b9e..63aee73 100644 --- a/neotest/examples/subtest.rs +++ b/neotest/examples/subtest.rs @@ -6,27 +6,27 @@ mod test { fn test_string_default() { let sut = String::default(); - subtest! { |string_is_empty| + subtest!(string_is_empty, { assert!(sut.is_empty()); - } - subtest! { |string_has_zero_len| + }); + subtest!(string_has_zero_len, { assert_eq!(sut.len(), 0); - } + }) } #[neotest(parameter = cap as [10, 42, 64])] fn test_vec_with_capacity(cap: usize) { let sut: Vec = Vec::with_capacity(cap); - subtest! { |capacity_is_set_to_input| + subtest!(capacity_is_set_to_input, { assert_eq!(sut.capacity(), cap); - } - subtest! { |vec_is_empty| + }); + subtest!(vec_is_empty, { assert!(sut.is_empty()); - } - subtest! { |vec_size_is_zero| + }); + subtest!(vec_size_is_zero, { assert_eq!(sut.len(), 0); - } + }) } } diff --git a/neotest/src/matcher.rs b/neotest/src/matcher.rs index 05dc09f..506d231 100644 --- a/neotest/src/matcher.rs +++ b/neotest/src/matcher.rs @@ -163,15 +163,15 @@ mod test { const VALUE: u32 = 5; let matcher = Le(VALUE); - subtest! {|matches_less| + subtest!(matches_less, { assert!(matcher.matches(VALUE - 1)); - } - subtest! {|matches_equal| + }); + subtest!(matches_equal, { assert!(matcher.matches(VALUE)); - } - subtest! {|does_not_match_greater| + }); + subtest!(does_not_match_greater, { assert!(!matcher.matches(VALUE + 1)); - } + }); } #[crate::neotest] @@ -179,15 +179,15 @@ mod test { const VALUE: u32 = 5; let matcher = Ge(VALUE); - subtest! {|matches_greater| + subtest!(matches_greater, { assert!(matcher.matches(VALUE + 1)); - } - subtest! {|matches_equal| + }); + subtest!(matches_equal, { assert!(matcher.matches(VALUE)); - } - subtest! {|does_not_match_less| + }); + subtest!(does_not_match_less, { assert!(!matcher.matches(VALUE - 1)); - } + }); } #[crate::neotest] @@ -195,15 +195,15 @@ mod test { const VALUE: u32 = 5; let matcher = Lt(VALUE); - subtest! {|matches_less| + subtest!(matches_less, { assert!(matcher.matches(VALUE - 1)); - } - subtest! {|does_not_match_equal| + }); + subtest!(does_not_match_equal, { assert!(!matcher.matches(VALUE)); - } - subtest! {|does_not_match_greater| + }); + subtest!(does_not_match_greater, { assert!(!matcher.matches(VALUE + 1)); - } + }); } #[crate::neotest] @@ -211,15 +211,15 @@ mod test { const VALUE: u32 = 5; let matcher = Gt(VALUE); - subtest! {|matches_greater| + subtest!(matches_greater, { assert!(matcher.matches(VALUE + 1)); - } - subtest! {|does_not_match_equal| + }); + subtest!(does_not_match_equal, { assert!(!matcher.matches(VALUE)); - } - subtest! {|does_not_match_less| + }); + subtest!(does_not_match_less, { assert!(!matcher.matches(VALUE - 1)); - } + }); } #[crate::neotest] @@ -227,15 +227,15 @@ mod test { const VALUE: u32 = 5; let matcher = Eq(VALUE); - subtest! {|does_not_match_greater| + subtest!(does_not_match_greater, { assert!(!matcher.matches(VALUE + 1)); - } - subtest! {|matches_equal| + }); + subtest!(matches_equal, { assert!(matcher.matches(VALUE)); - } - subtest! {|does_not_match_less| + }); + subtest!(does_not_match_less, { assert!(!matcher.matches(VALUE - 1)); - } + }); } #[crate::neotest] @@ -243,27 +243,27 @@ mod test { const VALUE: u32 = 5; let matcher = Ne(VALUE); - subtest! {|matches_greater| + subtest!(matches_greater, { assert!(matcher.matches(VALUE + 1)); - } - subtest! {|does_not_match_equal| + }); + subtest!(does_not_match_equal, { assert!(!matcher.matches(VALUE)); - } - subtest! {|matches_less| + }); + subtest!(matches_less, { assert!(matcher.matches(VALUE - 1)); - } + }); } #[crate::neotest] fn test_any() { let matcher = Any; - subtest! {|matches_int| + subtest!(matches_int, { assert!(matcher.matches(5)); - } - subtest! {|matches_string| + }); + subtest!(matches_string, { assert!(matcher.matches("hello world")); - } + }); } #[crate::neotest] @@ -271,41 +271,41 @@ mod test { const VALUE: u32 = 5; let matcher = Not(Ge(VALUE)); // lt - subtest! {|negates_input| - subtest! {|does_not_match_greater| + subtest!(negates_input, { + subtest!(does_not_match_greater, { assert!(!matcher.matches(VALUE + 1)); - } - subtest! {|does_not_match_equal| + }); + subtest!(does_not_match_equal, { assert!(!matcher.matches(VALUE)); - } - subtest! {|matches_less| + }); + subtest!(matches_less, { assert!(matcher.matches(VALUE - 1)); - } - } + }); + }); } #[crate::neotest] fn test_is_true() { let matcher = IsTrue; - subtest! {|matches_true| + subtest!(matches_true, { assert!(matcher.matches(true)); - } - subtest! {|does_not_match_false| + }); + subtest!(does_not_match_false, { assert!(!matcher.matches(false)); - } + }); } #[crate::neotest] fn test_is_false() { let matcher = IsFalse; - subtest! {|matches_false| + subtest!(matches_false, { assert!(matcher.matches(false)); - } - subtest! {|does_not_match_true| + }); + subtest!(does_not_match_true, { assert!(!matcher.matches(true)); - } + }); } struct BoolLike(bool); @@ -320,47 +320,47 @@ mod test { fn test_is_truthy() { let matcher = IsTruthy; - subtest! {|matches_truthy_value| + subtest!(matches_truthy_value, { assert!(matcher.matches(BoolLike(true))); - } - subtest! {|does_not_match_falsey_value| + }); + subtest!(does_not_match_falsey_value, { assert!(!matcher.matches(BoolLike(false))); - } + }); } #[crate::neotest] fn test_is_falsey() { let matcher = IsFalsey; - subtest! {|matches_falsey_value| + subtest!(matches_falsey_value, { assert!(matcher.matches(BoolLike(false))); - } - subtest! {|does_not_match_truthy_value| + }); + subtest!(does_not_match_truthy_value, { assert!(!matcher.matches(BoolLike(true))); - } + }); } #[crate::neotest] fn test_is_none() { let matcher = IsNone; - subtest! {|matches_none| + subtest!(matches_none, { assert!(matcher.matches(None::<()>)); - } - subtest! {|does_not_match_some| + }); + subtest!(does_not_match_some, { assert!(!matcher.matches(Some(42))); - } + }); } #[crate::neotest] fn test_is_some() { let matcher = IsSome; - subtest! {|matches_some| + subtest!(matches_some, { assert!(matcher.matches(Some(42))); - } - subtest! {|does_not_match_none| + }); + subtest!(does_not_match_none, { assert!(!matcher.matches(None::<()>)); - } + }); } }