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) => { ... };
}

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

Be careful when using this code, it's not being tested!
test_derive!{
    super::derive_interesting {
        struct A {
            a: i32,
            b: i32,
        }
    }
    expands to {
        impl ::Interesting for A {
            fn is_interesting(&self) -> bool {
                match *self {
                    A { a: ref __binding_0, b: ref __binding_1, } => {
                        false ||
                            ::Interesting::is_interesting(__binding_0) ||
                            ::Interesting::is_interesting(__binding_1)
                    }
                }
            }
        }
    }
}