Skip to content

Assert equal pointers #1076

Open
Open
@rthier

Description

@rthier

I try to test some properties of zap log and I got this:

assert.Same(t, zapcore.ISO8601TimeEncoder, got.EncoderConfig.EncodeTime)

       Error:      Not same:
        	       expected: 0x6bb840 (func(time.Time, zapcore.PrimitiveArrayEncoder))(0x6bb840)
        	       actual  : 0x6bb840 (zapcore.TimeEncoder)(0x6bb840)

In this test the object types are different, but the pointer (address) are same.
Internally the function Same call function samePointers, but this function compare two object pointers and not if the address of each object are equal.

func samePointers(first, second interface{}) bool {

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 function reflect.ValueOf(i interface{}).Pointer()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions