testify
testify copied to clipboard
Assert ErrorIs(): failure message shows identical strings when errors differ only by memory address.
context
the Assert.ErrorIs() method seems to expect that if the errors are not equal that the error chain will differ. This however is not the case when the errors are identical but differ in memory address.
current result
Error: Target error should be in err chain:
expected: "ERROR"
in chain: "ERROR"
Test: TestAssertIs
expected result
the scenario described should still fail, but since the chains are identical, It might be helpful to have a different message.
files affected
https://github.com/stretchr/testify/blob/v1.8.1/assert/assertions.go#L1794-L1813
reproduce
type A struct {
Value bool
}
func (a *A) Error() string {
return "ERROR"
}
var aErr = A{}
func returnErr() error {
return &aErr
}
func TestAssertIs(t *testing.T) {
err := returnErr()
target := A{}
assert.ErrorIs(t, err, &target)
}