]> Cypherpunks repositories - gostls13.git/commitdiff
time: add tests for Tick, NewTicker with negative duration
authorShawn Smith <shawn.p.smith@gmail.com>
Mon, 6 Jan 2014 18:32:07 +0000 (10:32 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Mon, 6 Jan 2014 18:32:07 +0000 (10:32 -0800)
R=golang-codereviews, gobot, r, bradfitz
CC=golang-codereviews
https://golang.org/cl/37660044

src/pkg/time/tick_test.go

index d8a086ceb2548725c90ecd670571386d185d435e..32f4740ad93cbcaad8e2460fef270eef9046994c 100644 (file)
@@ -48,6 +48,24 @@ func TestTeardown(t *testing.T) {
        }
 }
 
+// Test the Tick convenience wrapper.
+func TestTick(t *testing.T) {
+       // Test that giving a negative duration returns nil.
+       if got := Tick(-1); got != nil {
+               t.Errorf("Tick(-1) = %v; want nil", got)
+       }
+}
+
+// Test that NewTicker panics when given a duration less than zero.
+func TestNewTickerLtZeroDuration(t *testing.T) {
+       defer func() {
+               if err := recover(); err == nil {
+                       t.Errorf("NewTicker(-1) should have panicked")
+               }
+       }()
+       NewTicker(-1)
+}
+
 func BenchmarkTicker(b *testing.B) {
        ticker := NewTicker(1)
        b.ResetTimer()