go-check / check

Rich testing for the Go language
Other
696 stars 182 forks source link

checkers: fix misleading error for c.Check(nil, Equals, "foo") #114

Closed mvo5 closed 5 years ago

mvo5 commented 5 years ago

With the introduction of the diff code in PR#100 a subtle bug was introduced. When doing something like:

err := c.Check(nil, Equals, osutil.ErrAlreadyLocked)

the error is the very misleading:

flock_test.go:149:
    c.Assert(nil, Equals, osutil.ErrAlreadyLocked)
... obtained = nil
... expected *errors.errorString = &errors.errorString{s:"cannot acquire lock, already locked"} ("cannot acquire lock, already locked")
... runtime error: invalid memory address or nil pointer dereference

This is because the diffworth() code does not properly check for nil. This PR fixes this and adds some tests around the nil handling in Equals.