Skip to content

Fix subset assertions panicking on incompatible map keys - #1982

Open
Companion wants to merge 1 commit into
stretchr:masterfrom
Companion:fix/subset-incompatible-map-keys
Open

Companion wants to merge 1 commit into
stretchr:masterfrom
Companion:fix/subset-incompatible-map-keys

Conversation

@Companion

Copy link
Copy Markdown

Fix

Map comparisons with different key types can panic instead of reporting an assertion result

These calls now return false and true respectively without panicking

assert.Subset(t, map[string]int{"1": 1}, map[int]int{1: 1})
assert.NotSubset(t, map[string]int{"1": 1}, map[int]int{1: 1})

Treat incompatible keys as missing and keep matching interface keys working without numeric or named type conversions

Tests

  • Reproduced seven regression cases panicking in both assertions before the fix
  • All 16 new cases and existing subset tests pass
  • Full race suite run with only four Windows symlink permission failures also reproduced on the unchanged base
  • All assertion tests pass with race detection when those four filesystem tests are excluded
  • Vet formatting and generation checks pass

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