diff options
| author | Michael Mc Donnell <michael@mcdonnell.dk> | 2020-02-20 16:01:08 -0800 |
|---|---|---|
| committer | Michael Mc Donnell <michael@mcdonnell.dk> | 2020-02-21 08:04:16 -0800 |
| commit | e1c8c8cf63b48c798c1954749e58e99c6cc50093 (patch) | |
| tree | 6ea879f51f1121b58fff5587550f0ed359cb3184 /src | |
| parent | 212aa3ea28d91a97d1e1261709c0b6e6790788e6 (diff) | |
| download | rust-e1c8c8cf63b48c798c1954749e58e99c6cc50093.tar.gz rust-e1c8c8cf63b48c798c1954749e58e99c6cc50093.zip | |
Test `Duration::new` panics on overflow
A `Duration` is created from a second and nanoseconds variable. The documentation says: "This constructor will panic if the carry from the nanoseconds overflows the seconds counter". This was, however, not tested in the tests. I doubt the behavior will ever regress, but it is usually a good idea to test all documented behavior.
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcore/tests/time.rs | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/libcore/tests/time.rs b/src/libcore/tests/time.rs index 273f1258bb0..c1fbdf7df76 100644 --- a/src/libcore/tests/time.rs +++ b/src/libcore/tests/time.rs @@ -12,6 +12,12 @@ fn creation() { } #[test] +#[should_panic] +fn new_overflow() { + let _ = Duration::new(::core::u64::MAX, 1_000_000_000); +} + +#[test] fn secs() { assert_eq!(Duration::new(0, 0).as_secs(), 0); assert_eq!(Duration::new(0, 500_000_005).as_secs(), 0); |
