-
Notifications
You must be signed in to change notification settings - Fork 1.7k
assert.Len: avoid printing the value of very large objects #1235
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
Conversation
|
An interesting issue I'm experiencing due to this issue is that no error is printed at all when the string representation of the slice is too long: In my case, the string representation had 248,649 characters. Cheers |
dolmen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need tests.
brackendawson
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Len assertion should be changed to utilize assert.truncatingFormat and the size limit of truncatingFormat made useful.
This way testify has consistent behavior with long test output.
|
#1646 is kind of related, but it addresses output so long that it isn't returned at all. It could be modified or built upon to reduce output to a sane limit rather than a possible limit. |
|
I would expect the change made here for Len to be included in #1646, and we close this old PR |
|
It's been.. a while since I created this PR and it got ignored. Hopefully #1646 can solve it. |
Summary
When testing the
Lenof very large objects, the error message can appear very long or just not appear at all. Having a "printing length limit" helps in keeping the console clean and ensures the messageshould have %d item(s), but has %dappears and can be read.Changes
A failed
Lenassertion will print the type of the object instead of its value if the actual length of the object is greater than100items.100is an arbitrary value and I'm open to changing it.Motivation
In my tests some slices have thousands of items and I find myself avoiding
assert.Len(t, items, expectedItems)in favour of
assert.True(t, len(items) == expectedItems, "expected %d items to be set", expectedItems)just because the console gets filled with thousands of values that take all available space and are thus not useful for debugging.
In very large slices no message appears, leaving an empty error behind.