Skip to content

assert.Len: use %v when formatting value#1086

Closed
benjaminjkraft wants to merge 1 commit intostretchr:masterfrom
Khan:benkraft.fix-len
Closed

assert.Len: use %v when formatting value#1086
benjaminjkraft wants to merge 1 commit intostretchr:masterfrom
Khan:benkraft.fix-len

Conversation

@benjaminjkraft
Copy link

Summary

Fix assert.Len's error message for non-%sable values.

Details

It was using %s, which doesn't work if the thing being len'ed is not a
[]string or similar. For example, assert.Len(t, []int{1}, 0) says
that [%!s(int=1)] should have 1 item(s), but has 0. Now it uses %v
which will work for almost anything.

It was using %s, which doesn't work if the thing being len'ed is not a
`[]string` or similar.  For example, `assert.Len(t, []int{1}, 0)` says
that `[%!s(int=1)] should have 1 item(s), but has 0`.  Now it uses `%v`
which will work for almost anything.
Copy link
Contributor

@wwade wwade left a comment

Choose a reason for hiding this comment

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

Looks good and matches the change I was planning to make 😄

wwade
wwade approved these changes Nov 29, 2022
@wwade
Copy link
Contributor

wwade commented Nov 29, 2022

@glesica @boyan-soubachov @mvdkleijn could someone please have a look at this one?

@dolmen
Copy link
Collaborator

dolmen commented Oct 31, 2023

@benjaminjkraft @k1ng440 @wwade Could you instead review #1485 which I plan to merge soon?

@dolmen dolmen added bug rejected/duplicate pkg-assert Change related to package testify/assert labels Oct 31, 2023
@dolmen dolmen closed this Oct 31, 2023
@dolmen dolmen changed the title Use %v when formatting objects in assert.Len assert.Len: use %v when formatting value May 30, 2025
@dolmen dolmen added assert.Len enhancement: output format Enhancement related to formatting of messages labels May 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

assert.Len bug enhancement: output format Enhancement related to formatting of messages pkg-assert Change related to package testify/assert rejected/duplicate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants