smarty / assertions

Fluent assertion-style functions used by goconvey and gunit. Can also be used in any test or application.
Other
100 stars 34 forks source link

ShouldEqual no longer works with functions #53

Closed KevinAnthony closed 1 year ago

KevinAnthony commented 1 year ago

Starting in 1.15.0 ShouldEqual no longer functions properly.

func Test(t *testing.T) {
    f := func() {}
    str := assertions.ShouldEqual(f, f)

    if len(str) != 0 {
        panic(str)
    }
}

This panics with:

{"Message":"Expected: (func())(0x0000000104b26d40)
Actual:   (func())(0x0000000104b26d40)
(Should equal, but there is a type difference within the two)!","Expected":"(func())(0x0000000104b26d40)","Actual":"(func())(0x0000000104b26d40)"}

This work in 1.13.1

mdwhatcott commented 1 year ago

Good catch. The spec is pretty clear in stating that:

Slice, map, and function types are not comparable (with ==). However, as a special case, a slice, map, or function value may be compared to the predeclared identifier nil.

Furthermore, reflect.DeepEqual won't even return true in the case that a nil func reference is compared with nil: https://go.dev/play/p/9DRZia53nFk

So, I'm trying to see the utility of supporting equality comparisons with ShouldEqual. Just curious, why are you comparing functions with ShouldEqual?

KevinAnthony commented 1 year ago

Interface implementation testing.

We have an interface that has a function, "GetHandler()" that returns the handler that was set on initialization.
This unit test ensures that the function passed into the struct isn't mutated, and is instead the same function that is passed back out"

mdwhatcott commented 1 year ago

@KevinAnthony - Pull v1.15.1 and see if that does the trick.

KevinAnthony commented 1 year ago

I know this is closed, but I wanted to update it and say it worked for us.

KevinAnthony commented 1 year ago

can you look at this PR in goconvey https://github.com/smartystreets/goconvey/pull/676 To update this bug in goconvey?