]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/binary: don't assume b.N > 0
authorMarcel van Lohuizen <mpvl@golang.org>
Fri, 18 Mar 2016 15:40:46 +0000 (16:40 +0100)
committerRuss Cox <rsc@golang.org>
Fri, 18 Mar 2016 15:54:51 +0000 (15:54 +0000)
Change-Id: I9e887a0b32baf0adc85fa9e4b85b319e8ef333e9
Reviewed-on: https://go-review.googlesource.com/20853
Reviewed-by: Russ Cox <rsc@golang.org>
src/encoding/binary/binary_test.go

index fc6ea9534a6115a9284fcd40ce72d5513c9ca628..fe75a00b33688bf0062c04bcfb5e8e61accb6031 100644 (file)
@@ -373,7 +373,7 @@ func BenchmarkReadStruct(b *testing.B) {
                Read(bsr, BigEndian, &t)
        }
        b.StopTimer()
-       if !reflect.DeepEqual(s, t) {
+       if b.N > 0 && !reflect.DeepEqual(s, t) {
                b.Fatalf("struct doesn't match:\ngot  %v;\nwant %v", t, s)
        }
 }
@@ -405,7 +405,7 @@ func BenchmarkReadInts(b *testing.B) {
                want.Array[i] = 0
        }
        b.StopTimer()
-       if !reflect.DeepEqual(ls, want) {
+       if b.N > 0 && !reflect.DeepEqual(ls, want) {
                b.Fatalf("struct doesn't match:\ngot  %v;\nwant %v", ls, want)
        }
 }
@@ -427,7 +427,7 @@ func BenchmarkWriteInts(b *testing.B) {
                Write(w, BigEndian, s.Uint64)
        }
        b.StopTimer()
-       if !bytes.Equal(buf.Bytes(), big[:30]) {
+       if b.N > 0 && !bytes.Equal(buf.Bytes(), big[:30]) {
                b.Fatalf("first half doesn't match: %x %x", buf.Bytes(), big[:30])
        }
 }