BurntSushi / BurntSushi/quickcheck

How to combine quickcheck 1+ with fake?

Open
#320 3 comments 10 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
2.8k
Forks
165
PR merge metrics
No merged PRs in 30d

Description

Following the [zero2production book](https://github.com/LukeMathWalker/zero-to-production) With `quickcheck = "0.9.2"`, `quickcheck_macros = "0.9.1"` and `fake = "~2.3"`, the following works, because the function `Arbitrary::arbitrary` expected a `Gen` trait, and `Gen` used to be a trait:

```rust
#[derive(Debug, Clone)]
struct ValidEmailFixture(pub String);

impl quickcheck::Arbitrary for ValidEmailFixture {
fn arbitrary(g: &mut G) -> Self {
let email = SafeEmail().fake_with_rng(g);
Self(email)
}
}

#[quickcheck_macros::quickcheck]
fn valid_emails_are_parsed_successfully(valid_email: ValidEmailFixture) -> bool {
SubscriberEmail::parse(valid_email.0).is_ok()
}
```

Then we pass the mutable reference `g` into `SafeEmail().fake_with_rng(g);` and it works - [`fake`](https://docs.rs/fake/latest/fake/) generates random valid emails.

However, in `quickcheck = "1"`, `quickcheck::Gen` is no trait anymore, only a struct. I haven't found out how to access the inner `rng: rand::rngs::SmallRng` of `Gen` to pass it into `SafeEmail().fake_with_rng` and get `fake` to work with `quickcheck`.

How is it still possible in 1+?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.