Skip to content

assert: fix NotElementsMatch failure message formatting - #1977

Open
ibrahimypr wants to merge 1 commit into
stretchr:masterfrom
ibrahimypr:fix/notelementsmatch-messages
Open

ibrahimypr wants to merge 1 commit into
stretchr:masterfrom
ibrahimypr:fix/notelementsmatch-messages

Conversation

@ibrahimypr

Copy link
Copy Markdown

Summary

Fix custom failure messages in NotElementsMatch and NotElementsMatchf.

Changes

Expand msgAndArgs when forwarding to Fail on both matching-list paths. Add full-output regression checks for empty and nonempty lists, with a formatted message and without a message.

Motivation

assert.NotElementsMatchf(t, []int{1}, []int{1}, "case %d", 42) currently prints [case %d 42] instead of case 42. Calls without a custom message print a spurious Messages: [] line. The argument slice is passed as a single argument instead of being expanded. This fixes message rendering without changing the assertion result.

Validation

  • All four regression cases fail before the fix and pass after it.
  • go test ./assert -run '^TestNotElementsMatch' -count=1
  • go test -race ./...
  • go vet ./...
  • go generate ./... produces no additional changes; Go and README formatting checks pass.

AI assistance: implemented and tested with OpenAI Codex.

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.

1 participant