1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
use crate::std_facade::{fmt, Box, Vec};
use core::any::Any;
use core::fmt::Display;
use core::result::Result;
use core::str::FromStr;
#[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");
}