rust/tests/run-pass/time.rs

31 lines
919 B
Rust
Raw Normal View History

2020-03-19 23:00:02 +01:00
// ignore-windows: TODO clock shims are not implemented on Windows
// compile-flags: -Zmiri-disable-isolation
use std::time::{SystemTime, Instant};
fn main() {
let now1 = SystemTime::now();
// Do some work to make time pass.
for _ in 0..10 { drop(vec![42]); }
let now2 = SystemTime::now();
assert!(now2 > now1);
let diff = now2.duration_since(now1).unwrap();
assert!(diff.as_micros() > 0);
assert_eq!(now1 + diff, now2);
assert_eq!(now2 - diff, now1);
2020-03-19 23:00:02 +01:00
let now1 = Instant::now();
// Do some work to make time pass.
for _ in 0..10 { drop(vec![42]); }
let now2 = Instant::now();
assert!(now2 > now1);
2020-03-31 17:53:27 +02:00
#[cfg(target_os = "linux")] // TODO: macOS does not support Instant subtraction
{
let diff = now2.duration_since(now1);
assert!(diff.as_micros() > 0);
assert_eq!(now1 + diff, now2);
assert_eq!(now2 - diff, now1);
}
2020-03-19 23:00:02 +01:00
}