Crate proptest_arbitrary_adapter

Crate proptest_arbitrary_adapter 

Source
Expand description

Provides the necessary glue to reuse an implementation of arbitrary::Arbitrary as a proptest::strategy::Strategy.

§Usage

Assuming you use test-strategy (which you should), using a strategy for a type that implements arbitrary::Arbitrary is as simple as:

#[proptest]
fn my_test(#[strategy(arb())] my_type: MyType) {
    // …
}

§Origin

This code is a copy of the unmaintained crate proptest-arbitrary-interop, with some additional improvements from open pull requests of the original’s repository.

§Caveats

It only works with types that implement arbitrary::Arbitrary in a particular fashion: those conforming to the requirements of ArbInterop. These are roughly “types that, when randomly-generated, don’t retain pointers into the random-data buffer wrapped by the arbitrary::Unstructured they are generated from”. Many implementations of arbitrary::Arbitrary will fit the bill, but certain kinds of “zero-copy” implementations of arbitrary::Arbitrary will not work. This requirement appears to be a necessary part of the semantic model of proptest – generated values have to own their pointer graph, no borrows. Patches welcome if you can figure out a way to not require it.

Structs§

ArbStrategy
ArbValueTree

Traits§

ArbInterop
The subset of possible arbitrary::Arbitrary implementations that this crate works with. The main concern here is the for<'a> Arbitrary<'a> business, which (in practice) decouples the generated Arbitrary value from the lifetime of the random buffer it’s fed; I can’t actually explain how, because Rust’s type system is way over my head.

Functions§

arb
Constructs a proptest::strategy::Strategy for a given arbitrary::Arbitrary type.
arb_sized
Constructs a proptest::strategy::Strategy for a given arbitrary::Arbitrary type, generating size bytes of random data as input to the arbitrary::Arbitrary type.