Macro synstructure::test_derive[][src]

macro_rules! test_derive {
    ($name : path { $($i : tt) * } expands to { $($o : tt) * }) => { ... };
    ($name : path { $($i : tt) * } expands to { $($o : tt) * } no_build) => { ... };
}
Expand description

Run a test on a custom derive. This macro expands both the original struct and the expansion to ensure that they compile correctly, and confirms that feeding the original struct into the named derive will produce the written output.

You can add no_build to the end of the macro invocation to disable checking that the written code compiles. This is useful in contexts where the procedural macro cannot depend on the crate where it is used during tests.

Usage

fn test_derive_example(_s: synstructure::Structure)
    -> Result<proc_macro2::TokenStream, syn::Error>
{
    Ok(quote::quote! { const YOUR_OUTPUT: &'static str = "here"; })
}

fn main() {
    synstructure::test_derive!{
        test_derive_example {
            struct A;
        }
        expands to {
            const YOUR_OUTPUT: &'static str = "here";
        }
    }
}