Struct proptest::test_runner::TestRunner
source · pub struct TestRunner { /* private fields */ }
Expand description
State used when running a proptest test.
Implementations§
source§impl TestRunner
impl TestRunner
sourcepub fn new(config: Config) -> Self
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.
sourcepub fn deterministic() -> Self
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.
sourcepub fn new_with_rng(config: Config, rng: TestRng) -> Self
pub fn new_with_rng(config: Config, rng: TestRng) -> Self
Create a fresh TestRunner
with the given configuration and RNG.
sourcepub fn new_rng(&mut self) -> TestRng
pub fn new_rng(&mut self) -> TestRng
Create a new, independent but deterministic RNG from the RNG in this runner.
sourcepub fn bytes_used(&self) -> Vec<u8> ⓘ
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.
sourcepub fn run<S: Strategy>(
&mut self,
strategy: &S,
test: impl Fn(S::Value) -> TestCaseResult,
) -> Result<(), TestError<<S as Strategy>::Value>>
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.
sourcepub fn run_one<V: ValueTree>(
&mut self,
case: V,
test: impl Fn(V::Value) -> TestCaseResult,
) -> Result<bool, TestError<V::Value>>
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.
sourcepub fn reject_local(&mut self, whence: impl Into<Reason>) -> Result<(), Reason>
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.
sourcepub fn flat_map_regen(&self) -> bool
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
impl Clone for TestRunner
source§fn clone(&self) -> TestRunner
fn clone(&self) -> TestRunner
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for TestRunner
impl Debug for TestRunner
source§impl Default for TestRunner
impl Default for TestRunner
Equivalent to: TestRunner::new(Config::default())
.
Auto Trait Implementations§
impl Freeze for TestRunner
impl !RefUnwindSafe for TestRunner
impl Send for TestRunner
impl Sync for TestRunner
impl Unpin for TestRunner
impl !UnwindSafe for TestRunner
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)