-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Assert equal pointers #1076
Comments
go-testdeep allows this: https://go.dev/play/p/6QAY0tfAOoQ |
https://pkg.go.dev/reflect#Value.Pointer says
Also An improvement without adding new API might be to change |
I've created #1296 |
OTOH it works as documented // 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. and users may always do assert.Equal(t, reflect.ValueOf(expected).Pointer(), reflect.ValueOf(actual).Pointer()) |
I try to test some properties of zap log and I got this:
In this test the object types are different, but the pointer (address) are same.
Internally the function
Same
call functionsamePointers
, but this function compare two object pointers and not if the address of each object are equal.testify/assert/assertions.go
Line 409 in 6241f9a
For me its ok this behavior, but I propose a new assert, something like
assert.SameAddress(t TestingT, referenceObject, actualObject interface{})
This new assert just check if de
uintptr
is the same value of referenceObject and actualObject using the functionreflect.ValueOf(i interface{}).Pointer()
The text was updated successfully, but these errors were encountered: