use std::any::Any;
use std::fmt::Debug;
use std::str::FromStr as _;
use proptest::test_runner::{FailurePersistence, PersistedSeed};
#[derive(Clone, Debug, PartialEq)]
pub struct FailedSeeds(pub Vec<&'static str>);
impl FailurePersistence for FailedSeeds {
fn load_persisted_failures2(&self, _source_file: Option<&'static str>) -> Vec<PersistedSeed> {
let Self(seeds) = self;
seeds.iter().map(|s| PersistedSeed::from_str(s).expect("malformed seed")).collect()
}
fn save_persisted_failure2(
&mut self,
source_file: Option<&'static str>,
seed: PersistedSeed,
shrunken_value: &dyn Debug,
) {
eprintln!("Test failed when: {:?}", shrunken_value);
eprintln!("To reproduce this failure please add the following line:");
eprintln!("\"{}\"", seed);
eprintln!("to the test config in file {}", source_file.expect("failed to get source file"));
}
fn box_clone(&self) -> Box<dyn FailurePersistence> {
Box::new(self.clone())
}
fn eq(&self, other: &dyn FailurePersistence) -> bool {
other.as_any().downcast_ref::<Self>().map_or(false, |x| x == self)
}
fn as_any(&self) -> &dyn Any {
self
}
}
#[macro_export]
macro_rules! failed_seeds_no_std {
($($seed:literal),*) => {
Some({
use alloc::{boxed::Box, vec};
Box::new(proptest_support::FailedSeeds(vec![$($seed),*]))
})
}
}
#[macro_export]
macro_rules! failed_seeds {
($($seed:literal),*) => {
Some({
Box::new(proptest_support::FailedSeeds(vec![$($seed),*]))
})
}
}