-
Notifications
You must be signed in to change notification settings - Fork 165
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
The proptest_derive crate & #[derive(Arbitrary)] #79
The proptest_derive crate & #[derive(Arbitrary)] #79
Conversation
…ature/initial-proptest-derive
Sorry for my delayed response here. I'll see if I can work through this this weekend.
All sound like a good plan to me. |
No problem ❤️ Take your time! :) |
/// strategies and then switch to nesting like so: | ||
/// | ||
/// ```ignore | ||
/// (1, 2, 3, 4, 5, 6, 7, 8, 9, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This nesting isn't going to produce a uniform distribution. This is why prop_oneof!
falls back to boxing everything so it can use a normal Union
if it's over the limit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see you're doing something with weights below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the idea is that:
prop_oneof![ w1 => e1, w2 => e2, w3 => e3 ]
can be rewritten in terms of:
prop_oneof![ w1 => e1, (w2 + w3) => prop_oneof![ w2 => e2, w3 => e3 ] ]
and it commutes, so you can also say:
prop_oneof![ (w1 + w2) => prop_oneof![ w1 => e1, w2 => e2 ], w3 => e3 ]
This is then applied for larger groupings (the max number that TupleUnion
supports - 1).
In practice this would differ from the distribution you get when using Union
+ boxing because you are sampling the PRNG more times; but it seems to be that the cost of boxing every part of the union outweighs this slight discrepancy so I'd like to avoid the boxing.
#[derive(Debug, Arbitrary)] | ||
#[proptest(params(u64))] | ||
struct TPIS { | ||
#[proptest(strategy = "\"a+\"")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How hard would it be to have a #[proptest(regex = "string")]
for String
and Vec<[u8]>
fields? It would make syntax like this nicer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not very hard I think; you could do this by adding another attribute regex
to the parser and then desugaring that to the same internals as strategy
uses in the attribute parser.
I can do this in a follow up PR if you like :)
(I agree #[proptest(strategy = "\"a+\"")]
looks suboptimal)
Does the plugin itself work with stable? I've made a pass through the code and it initially looks pretty good, though there's a lot I don't understand since this stuff is extremely new to me. I'll try to work through it in more detail this week. |
It should; I think I have tested it on stable a few times, but I don't remember exactly when the last time was, so it is possible I let some mistake slip through. To make sure everything beside |
Did you get a chance to review any more of this? |
I haven't. Sorry about that and how unresponsive I've been in general lately. I should have some time soon. |
Hey :) I'd love to make improvements to the Any chance you could review this? If you think it's unlikely that you'll get to it in the foreseeable future, I can publish this out of tree, but that will of course make dealing with breaking chances more difficult. |
I'm going to set myself a hard commitment this time so I stop letting this slide: I will review and likely merge this on Saturday. |
"[proptest_derive, ", stringify!($code), "]", | ||
" during #[derive(Arbitrary)]:\n", | ||
$msg, | ||
" Please see: https://PATH/TO/foo#", stringify!($code), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll need to update this once the location of the docs are selected. (Just making a note so this is easier to see later.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nicely spotted; I might have forgotten about this otherwise. =P
Merging this into the |
Is there a reason some of the
|
@AltSysrq probably just my editor being silly (using Windows can be painful...). Try running the tests without them and change to 644 or something if the tests all pass... :)
No sorry, never got around to writing more docs but I'd like to help out; we can take some inspiration from serde.rs; an mdbook might be fitting here... |
@Centril any idea about this error off hand? https://travis-ci.org/AltSysrq/proptest/jobs/447128611#L2502 The |
Never mind, figured it out |
@AltSysrq Hmm... this happened to me sometimes when I was using the wrong path when building locally; so my guess would be one of: a) that the Does this build locally with the branch tested or do you also get errors with that? I'm about to sleep now, so I'll check it out in the morning if you didn't solve it before :) |
@AltSysrq so... what was the problem? =P |
|
Aaah; that makes a lot of sense. :) |
This PR adds the crate
proptest_derive
to this repo.The advantage of not having this in a separate repo is that I expect both crates will be easier to maintain and test if they are in a single place. Another crate that does this is serde which sports its
serde_derive
crate here.The PR is pretty massive in size (sorry about that) but it is 100% consisting of additions and no code is touched outside of the
proptest-derive
directory. I recommend checking out my branch and starting from thetests
directory to see what is supported and what is explicitly rejected.I'm sure there are places where the code can be refactored and improved, but I'd like to avoid making too many changes to this PR. We can of course make design changes and code improvements later.
Some things TODO after merging this PR (to a separate branch, not
master
):Setup a workspace. Ideally, all the code for the
proptest
crate should go in its own directory in the root andproptest-derive
should also be in the root.Make sure
proptest-derive
is tested with Travis CI and AppVeyor CI. For now, I have not made any changes to.travis.yml
but there are plenty of tests (+50% of the code). These should all be run with a nightly compiler (becausecompiletest_rs
wants it forpretty
tests and becauseattr_literals
is unstable). Until we've ensured that tests are run, it would be inadvisable to make breaking changes toproptest
itself.I have to give you perms on crates.io so you can publish updates to
proptest-derive
at the same time asproptest
.Release a 0.1 of
proptest-derive
.Here are some TODOs into the future:
We should figure out what to do with self-recursive and mutually-recursive types. These are not supported at all and will blow the stack if attempted.
Write extensive documentation (ideally in the form of an mdbook (see Idea: Making a book and splashy website about proptest #36)). I haven't had the time to do that yet but I'll start on it ASAP.
Improve error messages with correct spans and such things.
Eventually use the custom error message API in https://internals.rust-lang.org/t/custom-error-diagnostics-with-procedural-macros-on-almost-stable-rust/8113 to segregate errors by warnings and so on...