Struct TestRunner

pub struct TestRunner { /* private fields */ }

State used when running a proptest test.

Implementations

impl TestRunner

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.

fn deterministic() -> Self

Create a fresh TestRunner with the standard deterministic RNG.

This is sugar for the following:

# use proptest::test_runner::*;
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.

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

Create a fresh TestRunner with the given configuration and RNG.

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

Returns the RNG for this test run.

fn new_rng(&mut self) -> TestRng

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

fn config(&self) -> &Config

Returns the configuration of this runner.

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.

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.

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.

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.

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

impl Clone for TestRunner

fn clone(&self) -> TestRunner

impl Debug for TestRunner

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

impl Default for TestRunner

fn default() -> Self

impl Display for TestRunner

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

Auto Trait Implementations

impl !RefUnwindSafe for TestRunner

impl !UnwindSafe for TestRunner

impl Freeze for TestRunner

impl Send for TestRunner

impl Sync for TestRunner

impl Unpin for TestRunner

impl UnsafeUnpin for TestRunner

Blanket Implementations

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for TestRunner where ST: ?Sized, DT: ?Sized,

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for TestRunner where ST: ?Sized, DT: ?Sized,

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

fn type_id(&self) -> TypeId

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

fn borrow(&self) -> &T

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

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

impl<T> CloneToUninit for TestRunner where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for TestRunner

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Read<Exclusive, BecauseExclusive> for TestRunner where T: ?Sized,

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

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

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

fn to_string(&self) -> String

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

fn into(self) -> U

Calls U::from(self).

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

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

type Error = never;
fn try_from(value: U) -> Result<T, never>

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

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

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

fn vzip(self) -> V