assert/tests: add Helper() in all testing.T mocks

Add an Helper() method to all mocks in tests of package 'assert'.
This commit is contained in:
Olivier Mengué 2023-07-11 21:54:19 +02:00
parent d2ddb5da5d
commit bf47cc8868

View File

@ -745,6 +745,9 @@ type bufferT struct {
buf bytes.Buffer
}
// Helper is like [testing.T.Helper] but does nothing.
func (bufferT) Helper() {}
func (t *bufferT) Errorf(format string, args ...interface{}) {
// implementation of decorate is copied from testing.T
decorate := func(s string) string {
@ -2791,6 +2794,9 @@ type mockTestingT struct {
args []interface{}
}
// Helper is like [testing.T.Helper] but does nothing.
func (mockTestingT) Helper() {}
func (m *mockTestingT) errorString() string {
return fmt.Sprintf(m.errorFmt, m.args...)
}
@ -2816,6 +2822,9 @@ func TestFailNowWithPlainTestingT(t *testing.T) {
type mockFailNowTestingT struct{}
// Helper is like [testing.T.Helper] but does nothing.
func (mockFailNowTestingT) Helper() {}
func (m *mockFailNowTestingT) Errorf(format string, args ...interface{}) {}
func (m *mockFailNowTestingT) FailNow() {}
@ -3141,12 +3150,13 @@ type errorsCapturingT struct {
errors []error
}
// Helper is like [testing.T.Helper] but does nothing.
func (errorsCapturingT) Helper() {}
func (t *errorsCapturingT) Errorf(format string, args ...interface{}) {
t.errors = append(t.errors, fmt.Errorf(format, args...))
}
func (t *errorsCapturingT) Helper() {}
func TestEventuallyWithTFalse(t *testing.T) {
t.Parallel()
@ -3393,6 +3403,9 @@ type captureTestingT struct {
msg string
}
// Helper is like [testing.T.Helper] but does nothing.
func (captureTestingT) Helper() {}
func (ctt *captureTestingT) Errorf(format string, args ...interface{}) {
ctt.msg = fmt.Sprintf(format, args...)
ctt.failed = true