An example of testing errors
()
| 22 | |
| 23 | // An example of testing errors |
| 24 | func ExampleErrors() { |
| 25 | assert := assert.To(nil) |
| 26 | err := errors.New("failure") |
| 27 | otherErr := errors.New("other failure") |
| 28 | assert.For("nil succeeded").ThatError(nil).Succeeded() |
| 29 | assert.For("nil failed").ThatError(nil).Failed() |
| 30 | assert.For("err succeeded").ThatError(err).Succeeded() |
| 31 | assert.For("err failed").ThatError(err).Failed() |
| 32 | assert.For("err equals").ThatError(err).Equals(err) |
| 33 | assert.For("err not equals").ThatError(err).Equals(otherErr) |
| 34 | assert.For("err deep equals").ThatError(err).DeepEquals(err) |
| 35 | assert.For("err deep not equals").ThatError(err).DeepEquals(otherErr) |
| 36 | assert.For("message").ThatError(err).HasMessage(err.Error()) |
| 37 | assert.For("wrong message").ThatError(err).HasMessage(otherErr.Error()) |
| 38 | // Output: |
| 39 | // Error:nil failed |
| 40 | // Expect failure |
| 41 | // Error:err succeeded |
| 42 | // Got `failure` |
| 43 | // Expect success |
| 44 | // Error:err not equals |
| 45 | // Got `failure` |
| 46 | // Expect == `other failure` |
| 47 | // Error:err deep not equals |
| 48 | // Got `failure` |
| 49 | // Expect deep == `other failure` |
| 50 | // Error:wrong message |
| 51 | // Got `failure` |
| 52 | // Expect has message `other failure` |
| 53 | } |
nothing calls this directly
no test coverage detected