[assert] Diff doesn't display pointer vs nil in time.Time

Open
#372 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
go
Domain
testing-qa

Research direction

Start by reproducing the reported assert.Equal and assert.EqualValues comparison with time.Time values whose *time.Location is nil versus initialized. Inspect the assertion diff output path and make the completed behavior show this distinction in the diff, then verify the original example no longer produces an empty Diff section.

Written by the indexing model from the issue text.

Description

bug input needed

When using assert.Equal(t, x, y) and assert.EqualValues(t, x, y), I run into the following issue where it errors but no diff is displayed. After digging down I discovered it's to do with time.Time and whether *time.Location is initialised.

Output from assert:

Error Trace:    store_test.go:70
Error:		Not equal: 
        expected: []*cache.Item{(*cache.Item)(0xc4201a2640), (*cache.Item)(0xc4201a2780)}
        received: []*cache.Item{(*cache.Item)(0xc42021e000), (*cache.Item)(0xc42021e140)}
		
	Diff:

Logging out the structs with "%#v" reveals the difference is in time.Time. See my manual diff below:

- ExpiresAt:time.Time{sec:0, nsec:0, loc:(*time.Location)(nil)},
+ ExpiresAt:time.Time{sec:0, nsec:0, loc:(*time.Location)(0x8bb580)},
Dominant language
Go
Stars
26.2k
Forks
1.9k
Avg merge
2d 4h
Merged PRs (30d)
2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from stretchr/testify

All issues in stretchr/testify

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.