Use (*testing.T).Helper to clean up test failures

PiperOrigin-RevId: 242647530
Change-Id: I1bf9ac1d664f452dc47ca670d408a73538cb482f
This commit is contained in:
Tamir Duberstein 2019-04-09 05:16:29 -07:00 committed by Shentubot
parent 05979a7547
commit cf4ed408c3
1 changed files with 6 additions and 9 deletions

View File

@ -15,7 +15,6 @@
package ilist
import (
"runtime"
"testing"
)
@ -30,20 +29,20 @@ type direct struct {
}
func verifyEquality(t *testing.T, entries []testEntry, l *List) {
t.Helper()
i := 0
for it := l.Front(); it != nil; it = it.Next() {
e := it.(*testEntry)
if e != &entries[i] {
_, file, line, _ := runtime.Caller(1)
t.Errorf("Wrong entry at index (%s:%d): %v", file, line, i)
t.Errorf("Wrong entry at index %d", i)
return
}
i++
}
if i != len(entries) {
_, file, line, _ := runtime.Caller(1)
t.Errorf("Wrong number of entries (%s:%d)", file, line)
t.Errorf("Wrong number of entries; want = %d, got = %d", len(entries), i)
return
}
@ -51,16 +50,14 @@ func verifyEquality(t *testing.T, entries []testEntry, l *List) {
for it := l.Back(); it != nil; it = it.Prev() {
e := it.(*testEntry)
if e != &entries[len(entries)-1-i] {
_, file, line, _ := runtime.Caller(1)
t.Errorf("Wrong entry at index (%s:%d): %v", file, line, i)
t.Errorf("Wrong entry at index %d", i)
return
}
i++
}
if i != len(entries) {
_, file, line, _ := runtime.Caller(1)
t.Errorf("Wrong number of entries (%s:%d)", file, line)
t.Errorf("Wrong number of entries; want = %d, got = %d", len(entries), i)
return
}
}