Skip to content

Commit c98ef6e

Browse files
Merge pull request #1423 from stretchr/add-Helper-method-in-tests
Add Helper() method in internal mocks and assert.CollectT
2 parents d2ddb5d + 8f73f15 commit c98ef6e

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

assert/assertions.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,6 +2008,9 @@ type CollectT struct {
20082008
errors []error
20092009
}
20102010

2011+
// Helper is like [testing.T.Helper] but does nothing.
2012+
func (CollectT) Helper() {}
2013+
20112014
// Errorf collects the error.
20122015
func (c *CollectT) Errorf(format string, args ...interface{}) {
20132016
c.errors = append(c.errors, fmt.Errorf(format, args...))

assert/assertions_test.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,9 @@ type bufferT struct {
745745
buf bytes.Buffer
746746
}
747747

748+
// Helper is like [testing.T.Helper] but does nothing.
749+
func (bufferT) Helper() {}
750+
748751
func (t *bufferT) Errorf(format string, args ...interface{}) {
749752
// implementation of decorate is copied from testing.T
750753
decorate := func(s string) string {
@@ -2791,6 +2794,9 @@ type mockTestingT struct {
27912794
args []interface{}
27922795
}
27932796

2797+
// Helper is like [testing.T.Helper] but does nothing.
2798+
func (mockTestingT) Helper() {}
2799+
27942800
func (m *mockTestingT) errorString() string {
27952801
return fmt.Sprintf(m.errorFmt, m.args...)
27962802
}
@@ -2816,6 +2822,9 @@ func TestFailNowWithPlainTestingT(t *testing.T) {
28162822

28172823
type mockFailNowTestingT struct{}
28182824

2825+
// Helper is like [testing.T.Helper] but does nothing.
2826+
func (mockFailNowTestingT) Helper() {}
2827+
28192828
func (m *mockFailNowTestingT) Errorf(format string, args ...interface{}) {}
28202829

28212830
func (m *mockFailNowTestingT) FailNow() {}
@@ -3141,12 +3150,13 @@ type errorsCapturingT struct {
31413150
errors []error
31423151
}
31433152

3153+
// Helper is like [testing.T.Helper] but does nothing.
3154+
func (errorsCapturingT) Helper() {}
3155+
31443156
func (t *errorsCapturingT) Errorf(format string, args ...interface{}) {
31453157
t.errors = append(t.errors, fmt.Errorf(format, args...))
31463158
}
31473159

3148-
func (t *errorsCapturingT) Helper() {}
3149-
31503160
func TestEventuallyWithTFalse(t *testing.T) {
31513161
t.Parallel()
31523162

@@ -3393,6 +3403,9 @@ type captureTestingT struct {
33933403
msg string
33943404
}
33953405

3406+
// Helper is like [testing.T.Helper] but does nothing.
3407+
func (captureTestingT) Helper() {}
3408+
33963409
func (ctt *captureTestingT) Errorf(format string, args ...interface{}) {
33973410
ctt.msg = fmt.Sprintf(format, args...)
33983411
ctt.failed = true

mock/mock_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ type MockTestingT struct {
132132
logfCount, errorfCount, failNowCount int
133133
}
134134

135+
// Helper is like [testing.T.Helper] but does nothing.
136+
func (MockTestingT) Helper() {}
137+
135138
const mockTestingTFailNowCalled = "FailNow was called"
136139

137140
func (m *MockTestingT) Logf(string, ...interface{}) {

require/requirements_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ type MockT struct {
2929
Failed bool
3030
}
3131

32+
// Helper is like [testing.T.Helper] but does nothing.
33+
func (MockT) Helper() {}
34+
3235
func (t *MockT) FailNow() {
3336
t.Failed = true
3437
}

0 commit comments

Comments
 (0)