-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add a quickcheck crate #14100
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
Add a quickcheck crate #14100
Conversation
The docs are taken from burntsushi's README, adjusted to pass the `rustdoc` testing (and to avoid first-person text).
👍 |
@huonw: Please add Andrew Gallant to the |
} | ||
|
||
/// Creates a shrinker with zero elements. | ||
pub fn empty_shrinker<A>() -> Box<Shrinker<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.
Should this just be replaced with box EmptyShrinker
?
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.
@BurntSushi said in irc: i think i added empty_shrinker because i was having a hard time getting type inference to kick in. e.g., if i use box EmptyShrinker as Box<Shrinker<A>>
, then the compiler yells at me about an unconstrained type.
This looks good to me, but I figure we should wait to hear from the rest of the team to see if we're okay adding another crate to rust proper. |
Addressed review. |
/// trait. | ||
/// | ||
/// The `A` type variable corresponds to the elements yielded by the iterator. | ||
pub trait Shrinker<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.
If this is moving into rust proper, should Shrinker
be removed in favor of making Box<Iterator<A>>
implement Iterator<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.
It probably could, but I was thinking of waiting until DST
so that Iterator
can just have impl Iterator<A> for Iterator<A>
(or something).
In any case, it's an easy change now/later.
What is the reasoning behind making this a separate crate instead of putting it in |
I personally like having smaller self-contained crates, and there's no requirement for this to be in I'm happy to be convinced otherwise. |
I agree, there's no need to put it in the test crate. |
Added @MrAlert's |
Rendered docs: http://huonw.github.io/rust/build/doc/quickcheck/index.html |
Can we print a different string for passing checks than "ok"? Unlike normal tests, passing checks do not guarantee that it remains correct for the extended number of trials (though one can argue that the same applies to the nondeterministic tests). Something like "{:d} checks passed" seems better. |
@lifthrasiir I think the "ok" is from the regular Rust unit testing (i.e., |
@BurntSushi The original output posted by @huonw includes "test check_sort ... ok", which I think misleading. It seems that the tester indeed prints a separate output ("[quickcheck] Passed {:u} tests."), but it is only enabled for |
//! * As of now, only functions with 3 or fewer parameters can be quickchecked. | ||
//! This limitation can be lifted to some `N`, but requires an implementation | ||
//! for each `n` of the `Testable` trait. | ||
//! * Functions that fail because of a stack overflow are not caught |
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.
Stack overflow should be generating a normal task failure. Is this bullet still true?
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.
It's a hard abort, not a failure.
@lifthrasiir The "ok" is definitely printed by the |
@kballard Agreed. Maybe it's a separate issue that possibly benefits other use cases. |
I'm thinking we could take a leaf out of the polymorphic-return-book of this implementation, and basically allow enum TestResult { Pass(StrBuf), Fail(StrBuf) }
#[test] fn normal() { ... }
#[test] fn advanced() -> TestResult { ... } And then returning a message would allow output like
(Just "randomly" editing the current output.) Or,
|
@huonw I don't think we need truly polymorphic return type. Whichever bit of code handles |
Floating point shrinking is a little ugly at the moment because it goes through two layers of `Box<Shrinker<A>>`s. Thanks to @alan_andrade for his help on this one.
Per the weekly meeting it was decided that it's probably a bit too early to really say if Rust wants this. I'm going to close and then (eventually) submit the patches back to @BurntSushi. Anyone who has code here may wish to submit their patch themselves (to retain authorship etc.): @MrAlert, @bjz. |
@huonw You can submit the patches back to @BurntSushi in MBOX format, which retains all the authorship information (including timestamp and commit message). |
Oh, even better; I'll do that at some point in the near future. |
Same trick also works on the individual commits, if you want to submit only some of them (e.g. because the first commit presumably mirrors the code @BurntSushi already has). |
…fig, r=Veykril Allow specifying what proc-macro server to run in rust_analyzer::load_cargo API Closes rust-lang/rust-analyzer#10516
Removing the semicolon of the last statement of an expressionless block may change the block type even if the statement's type is `()`. If the block type is `!` because of a systematic early return, typing it as `()` may make it incompatible with the expected type for the block (to which `!` is cast). Fix rust-lang#14100 changelog: [`unnecessary_semicolon`]: do not remove semicolon if it could change the block type from `!` to `()`
This pulls https://github.com/BurntSushi/quickcheck into the tree (:heart: @BurntSushi).
It also extends it to include a
#[quickcheck]
attribute like#[test]
that will run quickcheck on the annotated item (both functions and statics are supported) (thanks @MrAlert):It expands to a
#[test]
test and so will appear in a normal--test
build:Other changes include:
StrBuf
internally