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

mock: remove unnecessary fmt.Sprintf in assert.Fail #1673

Conversation

alexandear
Copy link
Contributor

Summary

The PR simplifies implementations of AssertNumberOfCalls, AssertCalled, AssertNotCalled functions by removing redundant fmt.Sprintf.

Changes

Remove fmt.Sprintf call inside assert.Fail.

Motivation

assert.Fail already formats msg with arguments, no need to add fmt.Sprintf, see it's declaration:

func Fail(t TestingT, failureMessage string, msgAndArgs ...interface{})

@alexandear alexandear closed this Nov 24, 2024
@ccoVeille
Copy link
Contributor

Why closing? Inactivity?

@alexandear alexandear deleted the refactor/mock-unnecessary-sprintf branch December 10, 2024 12:19
@@ -661,7 +661,7 @@ func (m *Mock) AssertNumberOfCalls(t TestingT, methodName string, expectedCalls
actualCalls++
}
}
return assert.Equal(t, expectedCalls, actualCalls, fmt.Sprintf("Expected number of calls (%d) does not match the actual number of calls (%d).", expectedCalls, actualCalls))
return assert.Equal(t, expectedCalls, actualCalls, "Expected number of calls (%d) does not match the actual number of calls (%d).", expectedCalls, actualCalls)
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we're doing this I'd also change this to assert.Equalf as we're advising people not to use the msgAndArgs variadic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants