MCPcopy Create free account
hub / github.com/stretchr/testify / Same

Function Same

assert/assertions.go:500–518  ·  view source on GitHub ↗

Same asserts that two pointers reference the same object. assert.Same(t, ptr1, ptr2) Both arguments must be pointer variables. Pointer variable sameness is determined based on the equality of both type and value.

(t TestingT, expected, actual interface{}, msgAndArgs ...interface{})

Source from the content-addressed store, hash-verified

498// Both arguments must be pointer variables. Pointer variable sameness is
499// determined based on the equality of both type and value.
500func Same(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool {
501 if h, ok := t.(tHelper); ok {
502 h.Helper()
503 }
504
505 same, ok := samePointers(expected, actual)
506 if !ok {
507 return Fail(t, "Both arguments must be pointers", msgAndArgs...)
508 }
509
510 if !same {
511 // both are pointers but not the same type & pointing to the same address
512 return Fail(t, fmt.Sprintf("Not same: \n"+
513 "expected: %p %#v\n"+
514 "actual : %p %#v", expected, expected, actual, actual), msgAndArgs...)
515 }
516
517 return true
518}
519
520// NotSame asserts that two pointers do not reference the same object.
521//

Callers 4

SameFunction · 0.92
SamefFunction · 0.70
TestSameFunction · 0.70
SameMethod · 0.70

Calls 3

samePointersFunction · 0.85
FailFunction · 0.70
HelperMethod · 0.65

Tested by 1

TestSameFunction · 0.56