eupn / macrotest

Test harness for declarative and procedural macros expansion via `cargo-expand`
48 stars 9 forks source link

Handle expansion failure #66

Open eupn opened 2 years ago

eupn commented 2 years ago

Closes #65.

Please check with this branch, @Emoun. Should you get no issues, I'll merge this and release a new version.

Emoun commented 2 years ago

Thanks for working on #65. I'll test out this branch as soon as I can and report back here.

Emoun commented 2 years ago

I found the following problems with expand_fail:

eupn commented 2 years ago

@Emoun can you show me the code for failing macro? I'll add this macro as an example/test if it's small enough. Does manually calling cargo expand on this macro produce an error (with a non-zero exit code)?

Emoun commented 2 years ago

I'm trying things on duplicate, but the specific call I'm trying is:

#[duplicate::duplicate(refs(T); [& T]; [T])]
fn from(x: refs(Bits<1, false>)) -> bool {
    x.value == 1
}

Expanding this will panic in duplicate because of wrong use. You can try it out on the branch i'm using. The specific call is at tests/default_features/test/parameters_not_encapsulated.rs and the use of macrotest is at tests/default_features/mod.rs:46

I tried running cargo expand on a different project that used duplicate, where I added the wrong code, and I can see that cargo expand does return 0 as an exit code, even though it also shows that the macro panicked.

Emoun commented 2 years ago

Btw, I have cargo-expand v1.0.9

eupn commented 2 years ago

@Emoun, thank you! I'll explore this issue further.

eupn commented 2 years ago

@Emoun Indeed, cargo outputs expansion errors (such as proc macro panics) into STDERR while returning zero exit code. I've made some changes to handle this, could you check again?

Potentially will close #67.

Emoun commented 2 years ago

I'll have a look at it this weekend and report back.

Emoun commented 2 years ago

I've given the update a try and, in short, it seems for me to work well enough to be usable for my use cases.

I found one issue that I think is critical, though I specifically don't use macrotest in this way. As such, it is not blocking to me specifically:

Below are some of the irregularities I have found. While I think they should be addressed, they are not blocking for my use cases and mostly affect usability.

Emoun commented 2 years ago

@eupn, do you have an ETA on when this might get merged and an eventual new release? This PR and the changes currently in master would be really nice to get into a new release.

Thank you for all your hard work on this nice crate.

eupn commented 2 years ago

@Emoun thanks for kind words! I'll try my best to publish a new release next week.

Emoun commented 2 years ago

@eupn, sorry to bother again, but I'm still very much interested in this PR getting merged/released even without the last few fixes I highlighted above. I hope you can find some time to look into it.