pub struct TestRunner { /* private fields */ }
Expand description

State used when running a proptest test.

Implementations§

source§

impl TestRunner

source

pub fn new(config: Config) -> Self

Create a fresh TestRunner with the given configuration.

The runner will use an RNG with a generated seed and the default algorithm.

In no_std environments, every TestRunner will use the same hard-coded seed. This seed is not contractually guaranteed and may be changed between releases without notice.

source

pub fn deterministic() -> Self

Create a fresh TestRunner with the standard deterministic RNG.

This is sugar for the following:

let config = Config::default();
let algorithm = config.rng_algorithm;
TestRunner::new_with_rng(
    config,
    TestRng::deterministic_rng(algorithm));

Refer to TestRng::deterministic_rng() for more information on the properties of the RNG used here.

source

pub fn new_with_rng(config: Config, rng: TestRng) -> Self

Create a fresh TestRunner with the given configuration and RNG.

source

pub fn rng(&mut self) -> &mut TestRng

Returns the RNG for this test run.

source

pub fn new_rng(&mut self) -> TestRng

Create a new, independent but deterministic RNG from the RNG in this runner.

source

pub fn config(&self) -> &Config

Returns the configuration of this runner.

source

pub fn bytes_used(&self) -> Vec<u8>

Dumps the bytes obtained from the RNG so far (only works if the RNG is set to Recorder).

Panics

Panics if the RNG does not capture generated data.

source

pub fn run<S: Strategy>( &mut self, strategy: &S, test: impl Fn(S::Value) -> TestCaseResult ) -> Result<(), TestError<<S as Strategy>::Value>>

Run test cases against f, choosing inputs via strategy.

If any failure cases occur, try to find a minimal failure case and report that. If invoking f panics, the panic is turned into a TestCaseError::Fail.

If failure persistence is enabled, all persisted failing cases are tested first. If a later non-persisted case fails, its seed is persisted before returning failure.

Returns success or failure indicating why the test as a whole failed.

source

pub fn run_one<V: ValueTree>( &mut self, case: V, test: impl Fn(V::Value) -> TestCaseResult ) -> Result<bool, TestError<V::Value>>

Run one specific test case against this runner.

If the test fails, finds the minimal failing test case. If the test does not fail, returns whether it succeeded or was filtered out.

This does not honour the fork config, and will not be able to terminate the run if it runs for longer than timeout. However, if the test function returns but took longer than timeout, the test case will fail.

source

pub fn reject_local(&mut self, whence: impl Into<Reason>) -> Result<(), Reason>

Update the state to account for a local rejection from whence, and return Ok if the caller should keep going or Err to abort.

source

pub fn flat_map_regen(&self) -> bool

Increment the counter of flat map regenerations and return whether it is still under the configured limit.

Trait Implementations§

source§

impl Clone for TestRunner

source§

fn clone(&self) -> TestRunner

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for TestRunner

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for TestRunner

Equivalent to: TestRunner::new(Config::default()).

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Display for TestRunner

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V