Skip to content

fix: use %#v instead of %q in Subset/NotSubset error messages#1848

Open
veeceey wants to merge 1 commit intostretchr:masterfrom
veeceey:fix/not-subset-format-verb
Open

fix: use %#v instead of %q in Subset/NotSubset error messages#1848
veeceey wants to merge 1 commit intostretchr:masterfrom
veeceey:fix/not-subset-format-verb

Conversation

@veeceey
Copy link

@veeceey veeceey commented Feb 10, 2026

Summary

  • Fixes NotSubset (and Subset) error messages that use %q format verb, which produces broken output for non-string types (e.g., %!q(bool=true) for booleans, '\x01' for integers)
  • Changes to %#v (Go-syntax representation) to match how Subset already formats its "does not contain" failure messages
  • Updates corresponding test expectations to reflect the corrected output format

Before (broken):

Error: [%!q(bool=true)] is a subset of [%!q(bool=true)]

After (fixed):

Error: []bool{true} is a subset of []bool{true}

Fixes #1800

Test plan

  • All existing TestSubsetNotSubset tests pass with updated expectations
  • TestNotSubsetNil passes unchanged
  • TestNotSubsetWithSliceTooLongToPrint passes with updated expectations
  • TestNotSubsetWithMapTooLongToPrint passes with updated expectations
  • TestSubsetWithSliceTooLongToPrint and TestSubsetWithMapTooLongToPrint pass unchanged
  • Full test suite (go test ./...) passes with no regressions

🤖 Generated with Claude Code

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>
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.

assert.NotSubset incorrecly formats with %q

1 participant