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
#[cfg(not(disable_faketime))]
pub mod faketime;
pub mod system;
#[cfg(not(disable_faketime))]
pub use crate::faketime::{disable, enable, enable_and_write_millis, unix_time, write_millis};
#[cfg(disable_faketime)]
pub use crate::system::unix_time;
#[cfg(test)]
mod tests {
use crate::*;
#[cfg(disable_faketime)]
#[test]
fn test_system_time() {
let system_now = system::unix_time();
let now = unix_time();
assert!((now - system_now).as_secs() < 60);
}
#[cfg(not(disable_faketime))]
#[test]
fn test_mock_constant_time() {
let _faketime_file = enable_and_write_millis(123456).expect("enable faketime");
let now = unix_time();
assert_eq!(123, now.as_secs());
assert_eq!(456, now.subsec_millis());
}
}