Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a panic when comparing types where the underlying type is string #622

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.Name() != "string" {
e = spewConfig.Sdump(expected)
a = spewConfig.Sdump(actual)
} else {
Expand Down
15 changes: 15 additions & 0 deletions assert/assertions_test.go
Expand Up @@ -1791,3 +1791,18 @@ func TestErrorAssertionFunc(t *testing.T) {
})
}
}

type notstring string

// The code in the diff func used to check that the type was a kind of string
// and then do `var.(type)` on the variable containing the expected and actual
// values. This blew up when the type was a _kind_ of string but not actually
// a string.
func TestPanicOnStringLikeType(t *testing.T) {
f := func() {
mockT := new(testing.T)
Equal(mockT, notstring("value"), notstring("value2"))
}

NotPanics(t, f, "Should not panic when comparing string-ish types")
}