Skip to content

Commit

Permalink
Allow assert.Equal on string type alias without panicking on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
HaraldNordgren authored and georgelesica-wf committed Oct 2, 2018
1 parent 14d66a7 commit f2347ac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion assert/assertions.go
Expand Up @@ -1345,7 +1345,7 @@ func diff(expected interface{}, actual interface{}) string {
}

var e, a string
if ek != reflect.String {
if et != reflect.TypeOf("") {
e = spewConfig.Sdump(expected)
a = spewConfig.Sdump(actual)
} else {
Expand Down
8 changes: 8 additions & 0 deletions assert/assertions_test.go
Expand Up @@ -175,6 +175,8 @@ func TestIsType(t *testing.T) {

}

type myType string

func TestEqual(t *testing.T) {

mockT := new(testing.T)
Expand All @@ -200,13 +202,19 @@ func TestEqual(t *testing.T) {
if !Equal(mockT, uint64(123), uint64(123)) {
t.Error("Equal should return true")
}
if !Equal(mockT, myType("1"), myType("1")) {
t.Error("Equal should return true")
}
if !Equal(mockT, &struct{}{}, &struct{}{}) {
t.Error("Equal should return true (pointer equality is based on equality of underlying value)")
}
var m map[string]interface{}
if Equal(mockT, m["bar"], "something") {
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
Expand Down

0 comments on commit f2347ac

Please sign in to comment.