mirror of
https://github.com/stretchr/testify.git
synced 2025-05-31 11:42:44 +00:00
Allow assert.Equal on string type alias without panicking on failure
This commit is contained in:
parent
14d66a7ab5
commit
f2347ac6c9
@ -1345,7 +1345,7 @@ func diff(expected interface{}, actual interface{}) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var e, a string
|
var e, a string
|
||||||
if ek != reflect.String {
|
if et != reflect.TypeOf("") {
|
||||||
e = spewConfig.Sdump(expected)
|
e = spewConfig.Sdump(expected)
|
||||||
a = spewConfig.Sdump(actual)
|
a = spewConfig.Sdump(actual)
|
||||||
} else {
|
} else {
|
||||||
|
@ -175,6 +175,8 @@ func TestIsType(t *testing.T) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type myType string
|
||||||
|
|
||||||
func TestEqual(t *testing.T) {
|
func TestEqual(t *testing.T) {
|
||||||
|
|
||||||
mockT := new(testing.T)
|
mockT := new(testing.T)
|
||||||
@ -200,6 +202,9 @@ func TestEqual(t *testing.T) {
|
|||||||
if !Equal(mockT, uint64(123), uint64(123)) {
|
if !Equal(mockT, uint64(123), uint64(123)) {
|
||||||
t.Error("Equal should return true")
|
t.Error("Equal should return true")
|
||||||
}
|
}
|
||||||
|
if !Equal(mockT, myType("1"), myType("1")) {
|
||||||
|
t.Error("Equal should return true")
|
||||||
|
}
|
||||||
if !Equal(mockT, &struct{}{}, &struct{}{}) {
|
if !Equal(mockT, &struct{}{}, &struct{}{}) {
|
||||||
t.Error("Equal should return true (pointer equality is based on equality of underlying value)")
|
t.Error("Equal should return true (pointer equality is based on equality of underlying value)")
|
||||||
}
|
}
|
||||||
@ -207,6 +212,9 @@ func TestEqual(t *testing.T) {
|
|||||||
if Equal(mockT, m["bar"], "something") {
|
if Equal(mockT, m["bar"], "something") {
|
||||||
t.Error("Equal should return false")
|
t.Error("Equal should return false")
|
||||||
}
|
}
|
||||||
|
if Equal(mockT, myType("1"), myType("2")) {
|
||||||
|
t.Error("Equal should return false")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// bufferT implements TestingT. Its implementation of Errorf writes the output that would be produced by
|
// bufferT implements TestingT. Its implementation of Errorf writes the output that would be produced by
|
||||||
|
Loading…
x
Reference in New Issue
Block a user