Skip to content

Commit

Permalink
Rollup merge of #69354 - MichaelMcDonnell:duration_overflow_test, r=C…
Browse files Browse the repository at this point in the history
…entril

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.
  • Loading branch information
Dylan-DPC authored Feb 22, 2020
2 parents 541b407 + e1c8c8c commit 4f71270
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/libcore/tests/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 4f71270

Please sign in to comment.