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 1/4] 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 f3b8ddae0..c8d59d640 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 From b534400d1759dcd4ccef5b1ba11ec127eb6e0632 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Tue, 11 Jul 2023 21:54:58 +0200 Subject: [PATCH 2/4] require/tests: add Helper() method to all mocks of *testing.T --- require/requirements_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/require/requirements_test.go b/require/requirements_test.go index b62a5ba2c..7cb63a554 100644 --- a/require/requirements_test.go +++ b/require/requirements_test.go @@ -29,6 +29,9 @@ type MockT struct { Failed bool } +// Helper is like [testing.T.Helper] but does nothing. +func (MockT) Helper() {} + func (t *MockT) FailNow() { t.Failed = true } From e2ad95950ec6d51233ace09f87ae47ee96de93c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Tue, 11 Jul 2023 21:55:54 +0200 Subject: [PATCH 3/4] mock/tests: add method Helper() to all mock of *testing.T --- mock/mock_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mock/mock_test.go b/mock/mock_test.go index 04664d44b..2dea0873b 100644 --- a/mock/mock_test.go +++ b/mock/mock_test.go @@ -132,6 +132,9 @@ type MockTestingT struct { logfCount, errorfCount, failNowCount int } +// Helper is like [testing.T.Helper] but does nothing. +func (MockTestingT) Helper() {} + const mockTestingTFailNowCalled = "FailNow was called" func (m *MockTestingT) Logf(string, ...interface{}) { From 8f73f15d6939f4720ea8442714fdce556873b785 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Tue, 11 Jul 2023 22:17:10 +0200 Subject: [PATCH 4/4] assert.CollectT: add Helper() method Add Helper() method to CollectT like testing.T as we intend to add Helper() to the assert.TestingT interface. --- assert/assertions.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/assert/assertions.go b/assert/assertions.go index bdead180f..adac3ed4e 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -2008,6 +2008,9 @@ type CollectT struct { errors []error } +// Helper is like [testing.T.Helper] but does nothing. +func (CollectT) Helper() {} + // Errorf collects the error. func (c *CollectT) Errorf(format string, args ...interface{}) { c.errors = append(c.errors, fmt.Errorf(format, args...))