From bf47cc8868e89083fee4f5c6ae452c3c6f1d7d21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Tue, 11 Jul 2023 21:54:19 +0200 Subject: [PATCH] assert/tests: add Helper() in all testing.T mocks Add an Helper() method to all mocks in tests of package 'assert'. --- assert/assertions_test.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/assert/assertions_test.go b/assert/assertions_test.go index f3b8dda..c8d59d6 100644 --- a/assert/assertions_test.go +++ b/assert/assertions_test.go @@ -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