Commit 08bd9414 authored by Roger Peppe's avatar Roger Peppe

fix ErrorMatches

parent 689bdb3c
......@@ -181,14 +181,14 @@ type errorMatchesChecker struct {
// Check implements Checker.Check by checking that got is an error whose
// Error() matches args[0].
func (c *errorMatchesChecker) Check(got interface{}, args []interface{}, note func(key string, value interface{})) error {
if got == nil {
return errors.New("got nil error but want non-nil")
}
err, ok := got.(error)
if !ok {
note("got", got)
return BadCheckf("first argument is not an error")
}
if err == nil {
return errors.New("no error found")
}
return match(err.Error(), args[0], "error does not match regexp", note)
}
......
......@@ -978,18 +978,14 @@ got:
about: "ErrorMatches: nil error",
checker: qt.ErrorMatches,
got: nil,
args: []interface{}{".*"},
args: []interface{}{"some pattern"},
expectedCheckFailure: `
error:
bad check: first argument is not an error
got:
nil
`,
expectedNegateFailure: `
error:
bad check: first argument is not an error
got:
got nil error but want non-nil
got error:
nil
regexp:
"some pattern"
`,
}, {
about: "ErrorMatches: not enough arguments",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment