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

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:
    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.
2 files changed
tree: d293fcb19bdb3deacaf589ad37f4534d1342c8ae
  1. .gitignore
  2. .travis.yml
  5. TODO
  6. benchmark.go
  7. benchmark_test.go
  8. bootstrap_test.go
  9. check.go
  10. check_test.go
  11. checkers.go
  12. checkers_test.go
  13. export_test.go
  14. fixture_test.go
  15. foundation_test.go
  16. helpers.go
  17. helpers_test.go
  18. integration_test.go
  19. printer.go
  20. printer_test.go
  21. reporter.go
  22. reporter_test.go
  23. run.go
  24. run_test.go


Install the package with:

go get

Import it with:

import ""

and use check as the package name inside the code.

For more details, visit the project page:

and the API documentation: