-
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
Tracking issue for proptest_derive
#102
Comments
Thanks for putting this together. I do think it'd make sense to move some of the current |
:) I'll see if I can work on the base structure and some docs for the derive bits (particularly the error index...). |
Actually, would you mind letting me do the derive docs? I've found that writing docs is one of the better ways for me to fully learn a system. |
Sure :) I started on the "Error Index" a bit: https://gist.github.com/Centril/5be8f6383c888a16d75b8c46f4310e82 For writing the mdBook, I've been using |
One thing that occurred to me: It's fairly common to have #[derive(Debug)]
#[cfg_attr(test, derive(Arbitrary))]
struct _TheStruct {
#[cfg_attr(test, proptest(value = "NonArbitrary"))]
_a: NonArbitrary,
}
#[derive(Debug)]
struct NonArbitrary; I'm wondering it it'd make sense to have the macro put // In a crate that doesn't have a hard dependency on proptest
// It "just works"
#[derive(Debug, Arbitrary)]
struct _TheStruct {
#[proptest(value = "NonArbitrary"))]
_a: NonArbitrary,
}
#[derive(Debug)]
struct NonArbitrary;
// In a crate that wants to unconditionally export its `Arbitrary` implementation
// Need to opt out but otherwise fairly easy
#[derive(Debug, Arbitrary)]
#[proptest(always_derive)]
struct _TheStruct {
#[proptest(value = "NonArbitrary"))]
_a: NonArbitrary,
}
#[derive(Debug)]
struct NonArbitrary;
// In a crate that wants to export its `Arbitrary` implementation based on its own feature
// No explicit help for this, but you're in "advanced" territory anyway.
// It's a bit more cumbersome than in the status quo since you need to conditionally
// opt out of the implicit #[cfg(test)].
#[derive(Debug)]
#[cfg_attr(feature = "use_proptest", derive(Arbitrary))]
#[cfg_attr(feature = "use_proptest", proptest(always_derive))]
struct _TheStruct {
#[cfg_attr(feature = "use_proptest", proptest(value = "NonArbitrary"))]
_a: NonArbitrary,
}
#[derive(Debug)]
struct NonArbitrary; |
It looks like |
Started on the book: #104 |
I've been sorta thinking about this too; but I don't know if it can be made any better...
So the problem here is phase ordering... The only thing I could think of that would technically work right now is to have some cargo feature for Another thing worth trying is whether you can detect |
I went and checked the source of this and it appears that in match lit {
Lit::Str(lit) => lit.parse().ok(),
...
} I made a file #[macro_use]
extern crate proptest_derive;
#[derive(Debug, Arbitrary)]
struct Foo {
#[proptest(value = "4a")]
bar: u8,
} and changed the above match lit {
Lit::Str(lit) => {
println!("{:#?}", lit);
println!("{:#?}", lit.parse::<Expr>());
lit.parse().ok()
},
...
} and ran λ cargo test --test sandbox
Compiling proptest-derive v0.1.0 (D:\programming\proptest\proptest\proptest-derive)
LitStr {
token: Literal {
lit: Str_(
4a
),
suffix: None,
span: #0 bytes(467..471)
}
}
Ok(
Lit(
ExprLit {
attrs: [],
lit: Int(
LitInt {
token: Literal {
lit: Integer(
4
),
suffix: Some(
a
),
span: #0 bytes(467..471)
}
}
)
}
)
)
error: invalid suffix `a` for numeric literal
--> proptest-derive\tests\sandbox.rs:14:24
|
14 | #[proptest(value = "4a")]
| ^^^^
|
= help: the suffix must be one of the integral types (`u32`, `isize`, etc)
error: proc-macro derive produced unparseable tokens
--> proptest-derive\tests\sandbox.rs:12:17
|
12 | #[derive(Debug, Arbitrary)]
| ^^^^^^^^^
error: aborting due to 2 previous errors
error: Could not compile `proptest-derive`.
To learn more, run the command again with --verbose. We could check for this situation by seeing if we get However, it seems to me that the error message: error: invalid suffix `a` for numeric literal
--> proptest-derive\tests\sandbox.rs:14:24
|
14 | #[proptest(value = "4a")]
| ^^^^
|
= help: the suffix must be one of the integral types (`u32`, `isize`, etc) is pretty good... It points the user to the source of the error and explains it well... and so the added compile time to check this may not be worth it (it's not likely to occur often also...)? |
Do proc macros and their dependencies actually get included in the output binary? I assumed they were just loaded into the compiler and so having |
Yeah, I'm fine with leaving it. I mainly wasn't sure if "leaking" the invalid syntax pointed to some other kind of problem. |
@AltSysrq I don't think they get included in the binary no, but |
The The compile time point doesn't seem like a huge deal to me personally since the dependencies are fairly light (the whole thing takes 16s to build on my machine), but anyone who disagrees can still do the |
( Oh I see; this could work I think. In this case I think perhaps we should use a cargo feature tho (because it is simplest / least work needed to flick the switch) to either opt into gating on The cargo feature seems like something you could do by just changing a few lines in |
Just a thought, we should keep in mind that one use of |
This is exactly the situation I'm currently in as I'm using |
proptest-derive 0.1.0 is now available. There's still some outstanding things we'd like to improve, such as #106, but I think it makes sense to consider this particular issue complete. |
This issue tracks things we need to do before shipping
proptest_derive
0.1:proptest_derive
with (Travis) CI#[proptest(regex = "...")]
proptest
orprop
? or something else?weight
(shorthand:w
)strategy
value
params
no_params
skip
no_bound
filter
proptest_derive
for now?#[proptest(value = "4a")]
is accepted by the macro but of course is ultimately invalid syntax.The text was updated successfully, but these errors were encountered: