Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Helper() method in internal mocks and assert.CollectT #1423

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions assert/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1874,6 +1874,9 @@ type CollectT struct {
errors []error
}

// Helper is like [testing.T.Helper] but does nothing.
func (CollectT) Helper() {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the newly merged captureTestingT also get a Helper() method? (Or, should captureTestingT be replaced with CollectT?)


// Errorf collects the error.
func (c *CollectT) Errorf(format string, args ...interface{}) {
c.errors = append(c.errors, fmt.Errorf(format, args...))
Expand Down
9 changes: 9 additions & 0 deletions assert/assertions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,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 {
Expand Down Expand Up @@ -2485,6 +2488,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...)
}
Expand All @@ -2505,6 +2511,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() {}
Expand Down
3 changes: 3 additions & 0 deletions mock/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,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{}) {
Expand Down
3 changes: 3 additions & 0 deletions require/requirements_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,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
}
Expand Down