Skip to content

Commit e1c8c8c

Browse files
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.
1 parent 212aa3e commit e1c8c8c

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/libcore/tests/time.rs

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ fn creation() {
1111
assert_eq!(Duration::from_millis(4000), Duration::new(4, 0));
1212
}
1313

14+
#[test]
15+
#[should_panic]
16+
fn new_overflow() {
17+
let _ = Duration::new(::core::u64::MAX, 1_000_000_000);
18+
}
19+
1420
#[test]
1521
fn secs() {
1622
assert_eq!(Duration::new(0, 0).as_secs(), 0);

0 commit comments

Comments
 (0)