-
Notifications
You must be signed in to change notification settings - Fork 60
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
refactor: convert quickcheck -> proptest #229
Conversation
2a0e7c1
to
b1d972a
Compare
b1d972a
to
65bafd6
Compare
@huitseeker I've pushed a branch here 49a19f3 integrating your changes with my #239. If it's acceptable to you and @porcuquine, I would like to close this PR, and include the quickcheck->proptest change in #239 directly, since there's some work there that clarifies a few details (like the Arbitrary Afaiu, all the quickcheck tests in our test suite were written by me for the purpose of checking ScalarStore serialization, so it makes sense to me to me to fold this into my sequence of digestible PRs refactoring that (of which #237 and #239 are the first). Some specific thoughts:
The purpose of the weights in frequency was really for controlling generation of tree-like data, and it seems like
I don't think there should be any test failures from using Arbitrary derive. I added the missing cases in my branch, so should be easy to replace with the derives.
So, I have a solution to this issue I used in my #191 , where you can gate the Arbitrary Then you can enable Ofc if we want to just put the arbitrary instances in the main this doesn't matter, and might be too complicated. But it gives us a third option |
Actually, made a PR for #240 so that it's easier for people to look at |
Right, so there is an issue with the activation of test-only code with features, which is that features are additive. This interaction is with multi-crate environments:
Now bar effectively depends on bar with test-utils activated 🤦 I wrote about it in more details here: TL;DR: this solution quickly becomes indistinguishable from making the |
From your gist, I think possibly we could do something like:
to make sure "test-utils" can't be turned on outside of test, and must be turned on inside test. We could also do the latter half of this constraint at test-time: https://github.com/lurk-lang/lurk-rs/blob/186cedfbe159352afffef8aed7216e1a3c999a6c/ldon/src/lib.rs#L21-L36 Essentially, this is less of a general-purpose feature, and more of a work-around for the Rust limitation that you can't import another crate's All that said, it's a lot of complexity versus just adding e.g. Arbitrary publicly. |
Except So if you defined the code with your In other words, the only condition in which it’s both workable and meaningful to hide an If you intend your hidden
Agreed. |
Closing in favour of #240 |
This is meant to start the discussion on a conversion from quickcheck to proptest.
A few notes:
frequency
function, and replaced it withprop_oneof
. It may seem like the weighing of each alternative disappeared, but that is not the case: theprop_oneof!
macro supports weights, it just has a more simple form in case all those weighs are identical.Arbitrary
through proptest-derive. This is voluntary at this stage, for two reasons:Arbitrary
for large enums may have missed certain variants (e.g. the strategy forTag
does not generateChar
,Comm
,U64
orKey
), whereas a derived instance would not miss anything. That could create test failures I didn't want to deal with as part of this PR (I'll get to it eventually of course).Arbitrary
requires having access to the instance definitions of all the (transitively) composing fields. This essentially requires moving theArbitrary
impls from test modules to the main code (which can also help usability of the library). I wanted to make sure no one feels strongly against this.Note: this means that a ton of
impl Arbitrary for Foo
could disappear in a future PR, as soon as they are basically doing instance composition with no variability (e.g. exploring enums with empty variants likeFooTag
).Perf impact is minimal:
https://gist.github.com/huitseeker/d8a203e2bc56ea6043cb67a0e8386312