Allow assert.Equal on string type alias without panicking on failure

This commit is contained in:
Harald Nordgren 2018-09-11 20:52:35 +02:00 committed by George Lesica
parent 14d66a7ab5
commit f2347ac6c9
2 changed files with 9 additions and 1 deletions

View File

@ -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 {

View File

@ -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