Crate standard_test

Source
Expand description

§Standard Rust test suite

While not always explicitly documented, it is generally expected that the implementation of traits from Rust’s std has certain properties that cannot be expressed in the type system alone. For instance, most people assume that if a type T implements both Clone and Eq then x == x.clone() holds for all values x of T. Thus it’s often desirable for the impls to have such properties. In some cases (such as Eq) the properties are explicitly documented as required.

In any case, the only way to enforce correctness is to test the impls but that can be tedious and repetitive. This crate aims to help with that. It provides a set of standard tests that can be invoked easily.

The recommended way is to implement Arbitrary from crate arbitrary for your types and then invoke standard_checks!(YourTypeHere) macro to magically implement a test for your type. You can then use the one_iteration method within your fuzz loop.

The macro uses hacky “specialization” to run appropriate tests for your type based on which traits it implements.

Alternatively, if you for some reason cannot implement Arbitrary but can generate values differently, you can simply manually call approriate functions in the crate that provide the checks. For instance you could use kani to model-check that your implementation is correct.

Re-exports§

pub extern crate arbitrary;

Modules§

clone_eq
Checks combination of Clone + Eq.
clone_iterator_of_eq
Checks that cloned iterator yields the same values.
eq
Checks reflexivity.
eq_hash
Checks that for equal values equal bytes are given to a hasher.
exact_size_iterator
Checks that the length of ExactSizeIterator matches size_hint
fused_iterator
Checks that the iterator continues returning None once it reached the end.
iterator
Checks that size_hint behaves correctly.
partial_eq
Checks commutativity and transitivity.
partial_eq_into_iterator_partial_eq
Checks combination of IntoIterator + PartialEq where the items implement PartialEq.

Macros§

standard_checks
Automagically implements StandardChecks for your type given as paramter.

Traits§

StandardChecks
A trait implemented by types that have their traits auto-checked.