use core::any::Any;
use core::fmt::Display;
use core::result::Result;
use core::str::FromStr;
use crate::std_facade::{fmt, Box, Vec};
#[cfg(feature = "std")]
mod file;
mod map;
mod noop;
#[cfg(feature = "std")]
pub use self::file::*;
pub use self::map::*;
pub use self::noop::*;
use crate::test_runner::Seed;
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct PersistedSeed(pub(crate) Seed);
impl Display for PersistedSeed {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.0.to_persistence())
}
}
impl FromStr for PersistedSeed {
type Err = ();
fn from_str(s: &str) -> Result<Self, ()> {
Seed::from_persistence(s).map(PersistedSeed).ok_or(())
}
}
pub trait FailurePersistence: Send + Sync + fmt::Debug {
#[allow(deprecated)]
fn load_persisted_failures2(&self, source_file: Option<&'static str>)
-> Vec<PersistedSeed> {
self.load_persisted_failures(source_file)
.into_iter()
.map(|seed| PersistedSeed(Seed::XorShift(seed)))
.collect()
}
#[deprecated]
#[allow(unused_variables)]
fn load_persisted_failures(&self, source_file: Option<&'static str>)
-> Vec<[u8; 16]> {
panic!("load_persisted_failures2 not implemented");
}
#[allow(deprecated)]
fn save_persisted_failure2(
&mut self,
source_file: Option<&'static str>,
seed: PersistedSeed,
shrunken_value: &dyn fmt::Debug)
{
match seed.0 {
Seed::XorShift(seed) => self.save_persisted_failure(
source_file, seed, shrunken_value),
_ => (),
}
}
#[deprecated]
#[allow(unused_variables)]
fn save_persisted_failure(
&mut self,
source_file: Option<&'static str>,
seed: [u8;16],
shrunken_value: &dyn fmt::Debug)
{
panic!("save_persisted_failure2 not implemented");
}
fn box_clone(&self) -> Box<dyn FailurePersistence>;
fn eq(&self, other: &dyn FailurePersistence) -> bool;
fn as_any(&self) -> &dyn Any;
}
impl<'a, 'b> PartialEq<dyn FailurePersistence + 'b>
for dyn FailurePersistence + 'a {
fn eq(&self, other: &(dyn FailurePersistence + 'b)) -> bool {
FailurePersistence::eq(self, other)
}
}
impl Clone for Box<dyn FailurePersistence> {
fn clone(&self) -> Box<dyn FailurePersistence> {
self.box_clone()
}
}
#[cfg(test)]
mod tests {
use super::PersistedSeed;
use crate::test_runner::rng::Seed;
pub const INC_SEED: PersistedSeed =
PersistedSeed(
Seed::XorShift(
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]));
pub const HI_PATH: Option<&str> = Some("hi");
pub const UNREL_PATH: Option<&str> = Some("unrelated");
}