Macro assert_yields

Source
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

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,
        }
    }
);