-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Recursive arbitrary
calls
#451
Comments
Someone pointed to me that proptest_derive can solve a lot of this, which I think makes this less of a need. We went with a custom derive to implement a version of the arbitrary with Options that I highlighted. That would place this as lower priority on my end and happy to have it closed. |
Sorry for the delay, I had to step away for the past couple months to deal with some things at home. I'll be back working on things starting this weekend and will start triaging the issues that have come in. Given you found the derive crate, what exactly are you looking for/proposing? a utility function for generating strategies? additions to the derive macro or a completely separate macro? Thanks for the feedback |
Don't worry. I hope things are better at home. I'm honestly not sure what's the cleanest way to do this for the general case. Basically the idea is to allow every field to either be passed or auto-generated by calling its own arbitrary. In the custom derive we ended up with here, we just list the fields in order, each wrapped in an Option, as a tuple for the argument, and then have the check to either use Just or call "arbitrary" for the field. Maybe something like a builder pattern where the macro defines a new builder type. Then the user can set each field that is fixed to a given value, and then "finish" the build. The finishing would return a strategy for generating the base type where every field is either fixed to the provided value or is generated via "arbitrary". It could leverage the field annotations already present for the current proptest_derive to specify different ways to generate the fields that are not locked to a specific value. |
I frequently find myself having to call a hierarchy of value generation because I use
proptest::Arbitrary
on all types. Here's a simplified example:A concrete use case where this ends up appearing is when I have
T1 == Config
,T2 == Subsystem
andT3 == System
. Ideally, I'd like a way to have something likeT3::recursive_arbitrary()
that does whatrecursive_arbitrary_t3
does for me.I have working around this by doing
which is not an unreasonable workaround, but a bit more verbose than I'd have liked personally.
I'm not sure how this would work, but I've encountered this frequently enough that I'd imagine I'm not the only one. I'm open to helping provide the implementation for this if we have a reasonable idea how it could work.
The text was updated successfully, but these errors were encountered: