proptest-rs / proptest

Hypothesis-like property testing for Rust
Apache License 2.0
1.69k stars 158 forks source link

custom strategies in attribute macro #478

Closed cameron1024 closed 1 week ago

cameron1024 commented 3 months ago

This adds the ability to add custom strategies to parameters of a #[property_test] function:

#[property_test]
fn test_something(x: i32, #[strategy = "[0-9]*"] s: String) {
  // test body
}

This adds a second code path to codegen:

I've tried to retain span info, so error messages should appear at the correct place if you do things like add 2 strategies to a field, or use invalid syntax. For other stuff (e.g. passing non-strategies) we rely on rustc

matthew-russo commented 1 week ago

This got closed when i switched branch from master to main. I'll re-open against the main branch.