BurntSushi / quickcheck

Automated property based testing for Rust (with shrinking).
The Unlicense
2.4k stars 149 forks source link

Can the macro be modified to accept mutable variables? #144

Closed shepmaster closed 4 years ago

shepmaster commented 8 years ago

This currently fails:

quickcheck! {
    fn test_insertion_everything(mut xs: Vec<i32>) -> bool { true }
}

My macro-fu is weak, any idea how difficult that would be to add?

As a workaround, I can always immediate rebind the variable, but I'm lazy! 😼

BurntSushi commented 8 years ago

This is a known limitation. As the docs say. :-)

Note that this macro doesn't support mut or patterns in parameters.

cc @bluss (The original author of this amazing hackery.)

(I will also give this some thought, but I'm pretty deep in other stuff at the moment.)

bluss commented 8 years ago

Yes it can, but it's one of those tt-munchers. I extended it to do this after I showed the macro to burntsushi.

https://github.com/bluss/rust-itertools/blob/a048d32fb05d12f75ba36ae8f285204a08607255/tests/quick.rs#L171-L202

What the macro is doing: Counting : tokens, one : per function argument.

shepmaster commented 8 years ago

As the docs say

I'm not sure what you mean; what are these "docs" you speak of? 😵

In my (weak) defense, I was basically just grabbing the example from the README, so I never got into the docs at this particular time.

BurntSushi commented 8 years ago

@bluss Do you know if that macro is backward compatible with the one we have now? If so, I'd happily merge it. (I will also get around to it myself... eventually.)

bluss commented 8 years ago

Sure, it is compatible. It's using as fn(_, _) -> _ for the function pointer cast, so if it would be something it would be a type inference regression. But I don't think it happens, that cast always seems to work with just _ for the arguments and return value.

Maybe the allowed attribute use is a bit confusing (you write it on top of the prop function, but it gets used on top of the #[test] function). It works well for conditional compilation, though, that way.

clarfonthey commented 7 years ago

Adding onto this: it'd be nice if we recoded the macro using proc_macro so that it unbreaks all of these changes. Additionally, the attribute could be made stable using macros 1.2.

BurntSushi commented 7 years ago

@clarcharr That seems reasonable if it's possible. A few considerations:

  1. I'm not particularly interested in supporting any additional nightly-only features. So whatever we do, it should work on stable Rust.
  2. I probably won't do the initial implementation, but if it's simple, I'd be willing to maintain it.
spacejam commented 6 years ago

As someone who uses this crate all over the place I would benefit from this :)

BurntSushi commented 4 years ago

If this is still a problem, then I'd welcome a PR if it's fixable.