Skip to content

fix(assert): print unsigned integers as decimal, not hex in diff output - #1994

Open
ifauzeee wants to merge 1 commit into
stretchr:masterfrom
ifauzeee:fix/uint-hex-format
Open

ifauzeee wants to merge 1 commit into
stretchr:masterfrom
ifauzeee:fix/uint-hex-format

Conversation

@ifauzeee

Copy link
Copy Markdown

Summary

Closes #400.

assert.Equal and assert.EqualValues printed unsigned integers in hex format in diff output because formatUnequalValues used %#v, which renders uint values as 0x6a5 instead of 1701. This made error messages confusing and hard to read.

Fix

Added a formatValue helper that uses %v for unsigned integer kinds (uint through uintptr) to produce decimal output, while keeping %#v for all other types to preserve struct field names and string quotes. Updated both code paths in formatUnequalValues: the cross-type path (%T(%s)) and the same-type path.

Before

expected: float64(1700)
actual  : uint(0x6a5)

After

expected: float64(1700)
actual  : uint(1701)

Testing

  • TestFormatUnequalValues — extended with two new cases:
    • uint(1700) vs uint(1701) → 1700 / 1701 (same type, no prefix)
    • uint(1700) vs int(1701) → uint(1700) / int(1701) (cross type, with prefix)
  • go test -run TestFormatUnequalValues ./assert/ → PASS
  • go vet ./... → clean
  • gofmt -l assert/assertions.go assert/assertions_test.go → clean

Pre-existing failures in assert (4 symlink tests on Windows) and suite (panic/signature tests) are unrelated to this change — reproduced identically in a clean worktree at base commit 87a7b9d.

Backward compatibility

The only behavior change is that unsigned integers now display as decimal instead of hex in assertion failure messages. No API changes, no logic changes in equality checks.

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.

Equal diff prints uints in hex format

1 participant