pub trait ProptestResultExt<T, E>: Sealed {
// Required method
fn prop_assume_ok(self) -> Result<T, TestCaseError>
where E: Debug;
}Expand description
Extension trait for Result<T, E> to provide additional functionality
specifically for prop test cases.
Required Methods§
Sourcefn prop_assume_ok(self) -> Result<T, TestCaseError>where
E: Debug,
fn prop_assume_ok(self) -> Result<T, TestCaseError>where
E: Debug,
Converts a Result<T, E> into a Result<T, TestCaseError>, where the
Err case is transformed into a TestCaseError::Reject.
This is intended to be used like the prop_assume! macro, but for
fallible computations. If the result is Err, the test input is rejected
and a new input will be generated.
§Example
use proptest::prelude::*;
fn test_conversion(a: i32) -> Result<(), TestCaseError> {
// Reject the case if `a` cannot be converted to u8 (e.g., negative values)
let _unsigned: u8 = a.try_into().prop_assume_ok()?;
// ...rest of test...
Ok(())
}
proptest! {
#[test]
fn test_that_only_works_with_positive_integers(a in -10i32..10i32) {
test_conversion(a)?;
}
}