goconvey icon indicating copy to clipboard operation
goconvey copied to clipboard

ShouldEqual can't compare same value for custom type

Open mrLSD opened this issue 7 years ago • 4 comments

ShouldEqual can't compare same value for custom type

Examples:

			t := time.Now()
			So(t, ShouldEqual, t)

And:

			type test struct {
				A string
			}
			a1 := test{"test"}
			So(a1, ShouldEqual, a1)

All of them returns FAILED.

mrLSD avatar Mar 12 '18 14:03 mrLSD

also running into this. i have 2 values that are most definitely identical, yet ShouldEqual claims they aren't.

Dieterbe avatar Mar 29 '18 10:03 Dieterbe

When deep equal check is required, use ShouldResemble instead

type test struct {
  A string
}

a1 := test{"test"}
a2 := test{"test"}
a3 := test{"sup"}
So(a1, ShouldResemble, a2)
So(a1, ShouldResemble, a3)

dsmontoya avatar Apr 13 '18 22:04 dsmontoya

Same issue (even using latest commit available (044398e)). ShouldEqual doesn't work for type error while ShouldResemble did the trick.

//-------------------------------- service.go:
package main
import "errors"
func doSomething() (err error) {
	err = errors.New("a2")
	return
}
//-------------------------------- service_test.go:
package main
import (
	"errors"
	"testing"
	. "github.com/smartystreets/goconvey/convey"
)

func TestDoSomething1(t *testing.T) {
	Convey("Given", t, func() {
		Convey("When", func() {
			Convey("Then", func() {
				err := doSomething()
				So(err, ShouldEqual, errors.New("a2"))
			})
		})
	})
}
error

sbasile-ch avatar Dec 19 '18 19:12 sbasile-ch

Same problem, but I just found that the documentation has already metioned this point 😅
https://github.com/smartystreets/goconvey/wiki/Assertions#general-equality

Albelt avatar Sep 27 '21 09:09 Albelt