From 661a8d57dc869f5e60ffb64131edfc49470907c8 Mon Sep 17 00:00:00 2001 From: teor Date: Wed, 28 Apr 2021 11:14:02 +1000 Subject: [PATCH] Explain how to derive arbitrary impls --- book/src/dev/proptests.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/book/src/dev/proptests.md b/book/src/dev/proptests.md index 6b3c2cb9..5231ed2f 100644 --- a/book/src/dev/proptests.md +++ b/book/src/dev/proptests.md @@ -4,6 +4,13 @@ Zebra uses the [proptest](https://docs.rs/proptest/) crate for randomised proper Most types in `zebra-chain` have an `Arbitrary` implementation, which generates randomised test cases. +We try ti derive `Arbitrary` impls whenever possible, so that they autoamtically update when we make structural changes. +To derive, add the following attribute to the struct or enum: +```rust +#[cfg_attr(any(test, feature = "proptest-impl"), derive(Arbitrary))] +struct Example(u32); +``` + When we want to use those `Arbitrary` impls in proptests in other crates, we use the `proptest-impl` feature as a dev dependency: 1. in `zebra-chain`: make the `Arbitrary` impl depend on `#[cfg(any(test, feature = "proptest-impl"))]` 2. in the other crate: add zebra-chain as a dev dependency: `zebra-chain = { path = "../zebra-chain", features = ["proptest-impl"] }`