proptest-rs / proptest

Hypothesis-like property testing for Rust
Apache License 2.0
1.63k stars 152 forks source link

derive macro for Arbitrary is hard to find #463

Closed lolbinarycat closed 2 weeks ago

lolbinarycat commented 2 weeks ago

probably the biggest hurdle to using proptest is the need to manually implement Arbitrary for a type. the ability to have a derive macro, even if it was really limited (eg. only unit enums) would be incredibly useful.

obviously this derive macro couldn't figure out the best methods for shrinking a value and such, but often it wouldn't need to, as a lot of types (like unit enums) don't have any meaningful way they can be shrunk.

matthew-russo commented 2 weeks ago

Hi, this already exists:

https://proptest-rs.github.io/proptest/proptest-derive/index.html

https://crates.io/crates/proptest-derive

Let us know if this addresses your use case or if there are improvements you'd like to see

lolbinarycat commented 2 weeks ago

is there a reason for burying this all the way at the end? personally i would have reexported this gated under a derive feature flag like most other crates, but at the very least it should be referenced in the api docs for Arbitrary.

matthew-russo commented 2 weeks ago

The two crates are documented separately so first we document the proptest crate and then we document the proptest-derive crate. We can embed some more mention of the derive macro earlier on in the book and in the api docs

matthew-russo commented 2 weeks ago

It is mentioned in this area of the book about defining a canonical strategy: https://proptest-rs.github.io/proptest/proptest/tutorial/arbitrary.html?highlight=derive#defining-a-canonical-strategy-for-a-type

I'll add a note in the doc comments of Arbitrary.