fix: use %#v instead of %q in Subset/NotSubset error messages#1848
Open
veeceey wants to merge 1 commit intostretchr:masterfrom
Open
fix: use %#v instead of %q in Subset/NotSubset error messages#1848veeceey wants to merge 1 commit intostretchr:masterfrom
veeceey wants to merge 1 commit intostretchr:masterfrom
Conversation
The %q format verb is intended for quoted strings and treats byte/int
slice elements as rune literals (e.g., '\x01' instead of 1). For types
that don't implement the fmt.Stringer interface with %q, it produces
broken output like %!q(bool=true).
This changes NotSubset (and the unsupported-type errors in Subset) to
use %#v, which produces proper Go-syntax representation for all types.
This is consistent with how Subset already formats its "does not
contain" failure messages.
Before: [%!q(bool=true)] is a subset of [%!q(bool=true)]
After: []bool{true} is a subset of []bool{true}
Fixes stretchr#1800
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
NotSubset(andSubset) error messages that use%qformat verb, which produces broken output for non-string types (e.g.,%!q(bool=true)for booleans,'\x01'for integers)%#v(Go-syntax representation) to match howSubsetalready formats its "does not contain" failure messagesBefore (broken):
After (fixed):
Fixes #1800
Test plan
TestSubsetNotSubsettests pass with updated expectationsTestNotSubsetNilpasses unchangedTestNotSubsetWithSliceTooLongToPrintpasses with updated expectationsTestNotSubsetWithMapTooLongToPrintpasses with updated expectationsTestSubsetWithSliceTooLongToPrintandTestSubsetWithMapTooLongToPrintpass unchangedgo test ./...) passes with no regressions🤖 Generated with Claude Code