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

assert: fix error message formatting for NotContains #1362

Merged
merged 2 commits into from May 5, 2023

Conversation

wwade
Copy link
Contributor

@wwade wwade commented Mar 15, 2023

Summary

The assert.NotContains error messages now uses GoString() for formatting instead of Stringer().

Changes

  1. Renamed TestContainsFailMessage to TestContainsNotContainsFailMessage and refactored the test case to use a "test cases" structure.
  2. Changed \"%s\" to %#v in assert.NotContains.
  3. Added test cases covering both the "len()" / iterable failure messages as well as the Contains/NotContains failure message.

Motivation

The existing NotContains error messages are hard to read.

WAS:

"map[one:%!s(int=1)]" should not contain "one"

IS:

map[string]int{"one":1} should not contain "one"

I've renamed it to TestContainsNotContains and added a test case
structure so that I can use this test to validate the failure messages
from both Contains and NotContains,

There are no functional changes here, strictly refactoring. A new test
case will be added in a subsequent change.
It was using "%s" to format the s and contains arguments, but these
could be any type that supports iteration such as a map. In this case
of NotContains failing against a map, it would print something like:

   "map[one:%!s(int=1)]" should not contain "one"

Fix this using "%#v" as was already done for Contains and added test
cases covering both the "len()" / iterable failure messages as well as
the Contains/NotContains failure case.

The new message for this example map would be something like:

    map[string]int{"one":1} should not contain "one"
@wwade wwade marked this pull request as ready for review March 15, 2023 17:52
@wwade
Copy link
Contributor Author

wwade commented Mar 15, 2023

@mvdkleijn mind reviewing this one?

@wwade
Copy link
Contributor Author

wwade commented Mar 23, 2023

@boyan-soubachov mind having a look?

@wwade
Copy link
Contributor Author

wwade commented Mar 31, 2023

@glesica mind having a look at this?

@wwade
Copy link
Contributor Author

wwade commented May 5, 2023

@boyan-soubachov @glesica bump please.

Copy link
Collaborator

@boyan-soubachov boyan-soubachov left a comment

Choose a reason for hiding this comment

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

Thank you very much :)

@boyan-soubachov boyan-soubachov merged commit 437071b into stretchr:master May 5, 2023
3 checks passed
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.

None yet

3 participants