Struct Config
struct Config { ... }
Configuration for how a proptest test should be run.
Fields
cases: u32The number of successful test cases that must execute for the test as a whole to pass.
This does not include implicitly-replayed persisted failing cases.
The default is 256, which can be overridden by setting the
PROPTEST_CASESenvironment variable. (The variable is only considered when thestdfeature is enabled, which it is by default.)max_local_rejects: u32The maximum number of individual inputs that may be rejected before the test as a whole aborts.
The default is 65536, which can be overridden by setting the
PROPTEST_MAX_LOCAL_REJECTSenvironment variable. (The variable is only considered when thestdfeature is enabled, which it is by default.)max_global_rejects: u32The maximum number of combined inputs that may be rejected before the test as a whole aborts.
The default is 1024, which can be overridden by setting the
PROPTEST_MAX_GLOBAL_REJECTSenvironment variable. (The variable is only considered when thestdfeature is enabled, which it is by default.)max_flat_map_regens: u32The maximum number of times all
Flattencombinators will attempt to regenerate values. This puts a limit on the worst-case exponential explosion that can happen with nestedFlattens.The default is 1_000_000, which can be overridden by setting the
PROPTEST_MAX_FLAT_MAP_REGENSenvironment variable. (The variable is only considered when thestdfeature is enabled, which it is by default.)failure_persistence: Option<Box<dyn FailurePersistence>>Indicates whether and how to persist failed test results.
When compiling with "std" feature (i.e. the standard library is available), the default is
Some(Box::new(FileFailurePersistence::SourceParallel("proptest-regressions"))).Without the standard library, the default is
None, and no persistence occurs.See the docs of
FileFailurePersistenceandMapFailurePersistencefor more information.You can disable failure persistence with the
PROPTEST_DISABLE_FAILURE_PERSISTENCEenvironment variable but its not currently possible to set the persistence file with an environment variable. (The variable is only considered when thestdfeature is enabled, which it is by default.)source_file: Option<&'static str>File location of the current test, relevant for persistence and debugging.
Note the use of
&strrather thanPathto be compatible with#![no_std]use cases wherePathis unavailable.See the docs of
FileFailurePersistencefor more information on how it may be used for persistence.test_name: Option<&'static str>The fully-qualified name of the test being run, as would be passed to the test executable to run just that test.
This must be set if
forkistrue. Otherwise, it is unused. It is automatically set byproptest!.This must include the crate name at the beginning, as produced by
module_path!().fork: boolIf true, tests are run in a subprocess.
Forking allows proptest to work with tests which may fail by aborting the process, causing a segmentation fault, etc, but can be a lot slower in certain environments or when running a very large number of tests.
For forking to work correctly, both the
Strategyand the content of the test case itself must be deterministic.This requires the "fork" feature, enabled by default.
The default is
false, which can be overridden by setting thePROPTEST_FORKenvironment variable. (The variable is only considered when thestdfeature is enabled, which it is by default.)timeout: u32If non-zero, tests are run in a subprocess and each generated case fails if it takes longer than this number of milliseconds.
This implicitly enables forking, even if the
forkfield isfalse.The type here is plain
u32(rather thanOption<std::time::Duration>) for the sake of ergonomics.This requires the "timeout" feature, enabled by default.
Setting a timeout to less than the time it takes the process to start up and initialise the first test case will cause the whole test to be aborted.
The default is
0(i.e., no timeout), which can be overridden by setting thePROPTEST_TIMEOUTenvironment variable. (The variable is only considered when thestdfeature is enabled, which it is by default.)max_shrink_time: u32If non-zero, give up the shrinking process after this many milliseconds have elapsed since the start of the shrinking process.
This will not cause currently running test cases to be interrupted.
This configuration is only available when the
stdfeature is enabled (which it is by default).The default is
0(i.e., no limit), which can be overridden by setting thePROPTEST_MAX_SHRINK_TIMEenvironment variable. (The variable is only considered when thestdfeature is enabled, which it is by default.)max_shrink_iters: u32Give up on shrinking if more than this number of iterations of the test code are run.
Setting this to
std::u32::MAXcauses the actual limit to be four times the number of test cases.Setting this value to
0disables shrinking altogether.Note that the type of this field will change in a future version of proptest to better accommodate its special values.
The default is
std::u32::MAX, which can be overridden by setting thePROPTEST_MAX_SHRINK_ITERSenvironment variable. (The variable is only considered when thestdfeature is enabled, which it is by default.)max_default_size_range: usizeThe default maximum size to
proptest::collection::SizeRange. The default strategy for collections (likeVec) use collections in the range of0..max_default_size_range.The default is
100which can be overridden by setting thePROPTEST_MAX_DEFAULT_SIZE_RANGEenvironment variable. (The variable is only considered when thestdfeature is enabled, which it is by default.)result_cache: fn() -> Box<dyn ResultCache>A function to create new result caches.
The default is to do no caching. The easiest way to enable caching is to set this field to
basic_result_cache(though that is currently only available with thestdfeature).This is useful for strategies which have a tendency to produce duplicate values, or for tests where shrinking can take a very long time due to exploring the same output multiple times.
When caching is enabled, generated values themselves are not stored, so this does not pose a risk of memory exhaustion for large test inputs unless using extraordinarily large test case counts.
Caching incurs its own overhead, and may very well make your test run more slowly.
verbose: u32Set to non-zero values to cause proptest to emit human-targeted messages to stderr as it runs.
Greater values cause greater amounts of logs to be emitted. The exact meaning of certain levels other than 0 is subject to change.
- 0: No extra output.
- 1: Log test failure messages. In state machine tests, this level is used to print transitions.
- 2: Trace low-level details.
This is only available with the
stdfeature (enabled by default) since on nostd proptest has no way to produce output.The default is
0, which can be overridden by setting thePROPTEST_VERBOSEenvironment variable. (The variable is only considered when thestdfeature is enabled, which it is by default.)rng_algorithm: RngAlgorithmThe RNG algorithm to use when not using a user-provided RNG.
The default is
RngAlgorithm::default(), which can be overridden by setting thePROPTEST_RNG_ALGORITHMenvironment variable to one of the following:xs—RngAlgorithm::XorShiftcc—RngAlgorithm::ChaCha
(The variable is only considered when the
stdfeature is enabled, which it is by default.)
Implementations
impl Config
fn with_cases(cases: u32) -> SelfConstructs a
Configonly differing from thedefault()in the number of test cases required to pass the test successfully.This is simply a more concise alternative to using field-record update syntax:
# use Config; assert_eq!;fn with_source_file(source_file: &'static str) -> SelfConstructs a
Configonly differing from thedefault()in the source_file of the present test.This is simply a more concise alternative to using field-record update syntax:
# use Config; assert_eq!;fn clone_with_source_file(self: &Self, source_file: &'static str) -> SelfConstructs a
Configonly differing from the provided Config instance,self, in the source_file of the present test.This is simply a more concise alternative to using field-record update syntax:
# use Config; let a = with_source_file; let b = a.clone_with_source_file; assert_eq!; assert_eq!;fn with_failure_persistence<T>(failure_persistence: T) -> Self where T: FailurePersistence + 'staticConstructs a
Configonly differing from thedefault()in the failure_persistence member.This is simply a more concise alternative to using field-record update syntax:
# use ; assert_eq!;fn fork(self: &Self) -> boolReturn whether this configuration implies forking.
This method exists even if the "fork" feature is disabled, in which case it simply returns false.
fn timeout(self: &Self) -> u32Returns the configured timeout.
This method exists even if the "timeout" feature is disabled, in which case it simply returns 0.
fn max_shrink_iters(self: &Self) -> u32Returns the configured limit on shrinking iterations.
This takes into account the special "automatic" behaviour.
impl Clone for Config
fn clone(self: &Self) -> Config
impl Debug for Config
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl Default for Config
fn default() -> Self
impl Freeze for Config
impl PartialEq for Config
fn eq(self: &Self, other: &Config) -> bool
impl RefUnwindSafe for Config
impl Send for Config
impl StructuralPartialEq for Config
impl Sync for Config
impl Unpin for Config
impl UnsafeUnpin for Config
impl UnwindSafe for Config
impl<T> Any for Config
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Config
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Config
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for Config
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for Config
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for Config
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T, U> Into for Config
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Config
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Config
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>
impl<V, T> VZip for Config
fn vzip(self: Self) -> V