Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions assert/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,8 @@ func Same(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) b
if !same {
// both are pointers but not the same type & pointing to the same address
return Fail(t, fmt.Sprintf("Not same: \n"+
"expected: %p %#[1]v\n"+
"actual : %p %#[2]v",
"expected: %#[1]v (%[1]T)(%[1]p)\n"+
"actual : %#[2]v (%[2]T)(%[2]p)",
expected, actual), msgAndArgs...)
}

Expand Down
18 changes: 17 additions & 1 deletion assert/assertions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ func ptr(i int) *int {
func TestSame(t *testing.T) {
t.Parallel()

mockT := new(testing.T)
mockT := new(mockTestingT)

if Same(mockT, ptr(1), ptr(1)) {
t.Error("Same should return false")
Expand All @@ -650,6 +650,22 @@ func TestSame(t *testing.T) {
if !Same(mockT, p, p) {
t.Error("Same should return true")
}

t.Run("same object, different type", func(t *testing.T) {
type s struct {
i int
}
type sPtr *s
ps := &s{1}
dps := sPtr(ps)
if Same(mockT, dps, ps) {
t.Error("Same should return false")
}
expPat :=
`expected: &assert.s\{i:1\} \(assert.sPtr\)\((0x[a-f0-9]+)\)\s*\n` +
`\s+actual : &assert.s\{i:1\} \(\*assert.s\)\((0x[a-f0-9]+)\)`
Regexp(t, regexp.MustCompile(expPat), mockT.errorString())
})
}

func TestNotSame(t *testing.T) {
Expand Down