From f2347ac6c9c98ca14694f64f92c4b917954a6dc9 Mon Sep 17 00:00:00 2001 From: Harald Nordgren Date: Tue, 11 Sep 2018 20:52:35 +0200 Subject: [PATCH] Allow assert.Equal on string type alias without panicking on failure --- assert/assertions.go | 2 +- assert/assertions_test.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/assert/assertions.go b/assert/assertions.go index 5bdec56cd..7c3cbced7 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -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 { diff --git a/assert/assertions_test.go b/assert/assertions_test.go index 91b5ee911..7431094d8 100644 --- a/assert/assertions_test.go +++ b/assert/assertions_test.go @@ -175,6 +175,8 @@ func TestIsType(t *testing.T) { } +type myType string + func TestEqual(t *testing.T) { mockT := new(testing.T) @@ -200,6 +202,9 @@ 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)") } @@ -207,6 +212,9 @@ func TestEqual(t *testing.T) { 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