stretchr/testify

consider using String() method on types that implement fmt.Stringer

Open

#1,215 opened on Jun 24, 2022

View on GitHub
 (2 comments) (3 reactions) (0 assignees)Go (1,704 forks)batch import
help wantedinput neededpkg-assert

Repository metrics

Stars
 (25,958 stars)
PR merge metrics
 (Avg merge 6d 15h) (2 merged PRs in 30d)

Description

First of all, thanks for this great library! We use it quite extensively in go-libp2p.

We're running into the problem that the error output is unreadable for many types.

For example, we have a type peer.ID that's just a string (type peer.ID string), but the error output is practically unreadable:

Error:      	[]peer.ID{"\x12 \x92\xad \xd38\r\xadG\xf4\xd57\xee\xe5B\xa6\xffk\x80\xb2\xdda\xe5&\a\xc69\x80>D=\xfc}", "\x12 \f5;\xd7\xca\x12\xe6\x8cɷ\x00\xa71\x85\xb7|\x8brGO\xb2\xb0\xf9\xaa\"A\xee\xd3#eHH", "\x12 \xa8q3O\xd00\x16\x83JA\xa2L\x1e\xed2\x9a\xf87\x01~\xf8ڗ\x97\xdaT\xb1\xe2(\x89\xba\x15", "\x12 \xa3\xbb\xcb`\x8cV\xbb@Z\xd8%\xb3|}K\x90\a\xa7\xb5\xdeg\u0600|ʿ籐7\x8e\xc8"} does not contain "\x12 \xfd\x97\xf2?\x85?&\xc22el;\xac\xa4m\x1cj\xa4\xe3c\xcf\x00\x85u\xdb}:~3\xbf\x81\xaa"

Another example is a type that contains a byte slice, but has a nice string representation. But instead of using that one, require error message print the byte slice.

I'd be happy to contribute a PR, if this is something you would consider accepting.

Contributor guide