proptest_arbitrary/_std/
time.rs

1//! Arbitrary implementations for `std::time`.
2
3use super::*;
4use std::time::*;
5
6arbitrary!(Duration, SMapped<'a, (u64, u32), Self>;
7    static_map(any::<(u64, u32)>(), |(a, b)| Duration::new(a, b))
8);
9
10// Instant::now() "never" returns the same Instant, so no shrinking may occur!
11arbitrary!(Instant; Self::now());
12
13// Same for SystemTime.
14arbitrary!(SystemTime; Self::now());
15
16/*
17A possible logic for SystemTimeError:
18fn gen_ste() -> SystemTimeError {
19    (SystemTime::now() + Duration::from_millis(10)).elapsed().unwrap_err()
20}
21This may however panic from time to time. NTP could also ruin our day!
22*/
23
24#[cfg(test)]
25mod test {
26    no_panic_test!(
27        duration => Duration,
28        instant  => Instant,
29        system_time => SystemTime
30    );
31}