go-test / deep

Golang deep variable equality test that returns human-readable differences
MIT License
743 stars 54 forks source link

For types implementing Error, test more than just Error #29

Closed andrewmostello closed 4 years ago

andrewmostello commented 5 years ago

In the existing implementation, if a type implements Error, but has other values that differ, deep.Equal returns without reporting a diff. This is because it is only checking the value of the Error strings.

If a type implements Error, the Error strings should be evaluated, but then deep.Equal should continue to look for a diff. To cover this case, continue testing a and b after passing the Error check.

coveralls commented 5 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling f9c0e8ae13b6824514d872c43817715b09361bd3 on andrewmostello:master into 042da051cf3189d80f667339b822c7effac29cd6 on go-test:master.

daniel-nichter commented 4 years ago

Makes sense. Originally, I was thinking an error is its Error() string interface output, but that's not really true. There are "rich" errors like the ones you have in the test case, and these extra fields matter. Thanks for the thorough test case!