macro_rules! assert_yields {
({
#[ $(::)? $macro_path1:ident $(:: $macro_path2:ident)* $(( $($attrs:tt)* ))? ]
$item:item
}, {
$($expanded:tt)*
}) => { ... };
}Expand description
Asserts that the first code block with attribute macro yields the second code block.
The first code block must consist of a attribute macro and an item. The implementation function of the macro must
- present in the same scope with the same name as the attribute macro
- have a signature of
(macro_attributes: A, applied_item: I) -> Result<R, _>, whereAandIimplementFrom<proc_macro2::TokenStream>, andRimplementsInto<proc_macro2::TokenStream>
The second code block may consist of arbitrary tokens.
See also assert_expands! for macros
that modify the original input.
ยงExamples
use proc_macro_tester::assert_yields;
assert_yields!(
{
#[create_struct_without_id(NewPerson)]
struct Person {
id: u32,
name: String,
}
},
{
// do not write the original item here
// struct Person {
// id: u32,
// name: String,
// }
struct NewPerson {
name: String,
}
}
);