Skip to content

Commit 1670921

Browse files
tengufromskybradfitz
authored andcommitted
time: increase test coverage for Time.Sub
Existing tests don't check overflow and underflow case for subtraction monotonic time. Updates #17858 Change-Id: I95311440134c92eadd7d5e409a0fc7c689e9bf41 Reviewed-on: https://go-review.googlesource.com/107056 Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 224f807 commit 1670921

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/time/internal_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,8 @@ func CheckRuntimeTimerOverflow() {
7676
// So we fall back to hope: We hope we don't hang here.
7777
<-t.C
7878
}
79+
80+
var (
81+
MinMonoTime = Time{wall: 1 << 63, ext: -1 << 63, loc: UTC}
82+
MaxMonoTime = Time{wall: 1 << 63, ext: 1<<63 - 1, loc: UTC}
83+
)

src/time/time_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,8 @@ var subTests = []struct {
978978
{Date(2300, 1, 1, 0, 0, 0, 0, UTC), Date(2000, 1, 1, 0, 0, 0, 0, UTC), Duration(maxDuration)},
979979
{Date(2000, 1, 1, 0, 0, 0, 0, UTC), Date(2290, 1, 1, 0, 0, 0, 0, UTC), -290*365*24*Hour - 71*24*Hour},
980980
{Date(2000, 1, 1, 0, 0, 0, 0, UTC), Date(2300, 1, 1, 0, 0, 0, 0, UTC), Duration(minDuration)},
981+
{MinMonoTime, MaxMonoTime, minDuration},
982+
{MaxMonoTime, MinMonoTime, maxDuration},
981983
}
982984

983985
func TestSub(t *testing.T) {

0 commit comments

Comments
 (0)