-
-
Notifications
You must be signed in to change notification settings - Fork 7
Testing tool for comparing output of macro against expected source code #28
Comments
This is better than invoking proc macros directly as
|
@dtolnay I want to give it a try. It's ok? |
Sounds good! Thanks for taking a look. |
@dtolnay |
Oh, I see that you've updated the issue's description. I will update the |
Updated the API to be similar to @dtolnay what should be considered as "expected failure" case of |
There are no expected failures. If any cargo expand exits unsuccessful then it should fail the test. |
Published on crates.io: macrotest |
Added procedural macro example. Even though it has some issues (#6, #7), it works. |
Nice, looks like a great start. I filed some issues based on trying out the crate. I think we can close out this issue once those are fixed. Thanks! |
Thanks for the thorough review! Will fix as many as possible. |
@dtolnay issues are fixed |
Awesome! |
@dtolnay btw, which of your crates with macros/proc-macros (or crates that you know) would make use of this tool? I'd be happy to file a PR to some of those crates to employ |
I would like to try it in Serde because the logic inside Deserialize derives can be pretty complicated to reason about. serde-rs/serde#1117 |
Similar to what https://github.com/dtolnay/trybuild does for testing compilation failures.
See here and here for a basic test setup leveraging trybuild.
I would expect a very similar setup for testing macro expansion -- with a suite of test cases as *.rs files in some directory, adjacent to expected expanded output in *.expanded.rs files with corresponding names. For each test case the library would set up dependencies and stuff correctly then invoke cargo expand to expand macros and format the expanded code with rustfmt. Then the test case would fail if the expanded and formatted code differs from the expected output in the corresponding *.expanded.rs file.
The text was updated successfully, but these errors were encountered: