Rollup merge of #69354 - MichaelMcDonnell:duration_overflow_test, r=Centril

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.
This commit is contained in:
Dylan DPC 2020-02-22 18:43:07 +05:30 committed by GitHub
commit 4f71270d7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,6 +11,12 @@ fn creation() {
assert_eq!(Duration::from_millis(4000), Duration::new(4, 0));
}
#[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);