mirror of https://github.com/stretchr/testify.git
Merge pull request #60 from 2pi/EqualErrorWrapper
add wrapper around the `EqualError` functionpull/61/head
commit
ce71e91e8d
|
@ -65,6 +65,8 @@
|
||||||
//
|
//
|
||||||
// assert.NoError(t, errorObject [, message [, format-args]])
|
// assert.NoError(t, errorObject [, message [, format-args]])
|
||||||
//
|
//
|
||||||
|
// assert.EqualError(t, theError, errString [, message [, format-args]])
|
||||||
|
//
|
||||||
// assert.Implements(t, (*MyInterface)(nil), new(MyObject) [,message [, format-args]])
|
// assert.Implements(t, (*MyInterface)(nil), new(MyObject) [,message [, format-args]])
|
||||||
//
|
//
|
||||||
// assert.IsType(t, expectedObject, actualObject [, message [, format-args]])
|
// assert.IsType(t, expectedObject, actualObject [, message [, format-args]])
|
||||||
|
@ -110,6 +112,8 @@
|
||||||
//
|
//
|
||||||
// assert.NoError(errorObject [, message [, format-args]])
|
// assert.NoError(errorObject [, message [, format-args]])
|
||||||
//
|
//
|
||||||
|
// assert.EqualError(theError, errString [, message [, format-args]])
|
||||||
|
//
|
||||||
// assert.Implements((*MyInterface)(nil), new(MyObject) [,message [, format-args]])
|
// assert.Implements((*MyInterface)(nil), new(MyObject) [,message [, format-args]])
|
||||||
//
|
//
|
||||||
// assert.IsType(expectedObject, actualObject [, message [, format-args]])
|
// assert.IsType(expectedObject, actualObject [, message [, format-args]])
|
||||||
|
|
|
@ -191,3 +191,16 @@ func (a *Assertions) NoError(theError error, msgAndArgs ...interface{}) bool {
|
||||||
func (a *Assertions) Error(theError error, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) Error(theError error, msgAndArgs ...interface{}) bool {
|
||||||
return Error(a.t, theError, msgAndArgs...)
|
return Error(a.t, theError, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EqualError asserts that a function returned an error (i.e. not `nil`)
|
||||||
|
// and that it is equal to the provided error.
|
||||||
|
//
|
||||||
|
// actualObj, err := SomeFunction()
|
||||||
|
// if assert.Error(err, "An error was expected") {
|
||||||
|
// assert.Equal(err, expectedError)
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
|
func (a *Assertions) EqualError(theError error, errString string, msgAndArgs ...interface{}) bool {
|
||||||
|
return EqualError(a.t, theError, errString, msgAndArgs...)
|
||||||
|
}
|
||||||
|
|
|
@ -267,6 +267,23 @@ func TestErrorWrapper(t *testing.T) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEqualErrorWrapper(t *testing.T) {
|
||||||
|
assert := New(t)
|
||||||
|
mockAssert := New(new(testing.T))
|
||||||
|
|
||||||
|
// start with a nil error
|
||||||
|
var err error
|
||||||
|
assert.False(mockAssert.EqualError(err, ""),
|
||||||
|
"EqualError should return false for nil arg")
|
||||||
|
|
||||||
|
// now set an error
|
||||||
|
err = errors.New("some error")
|
||||||
|
assert.False(mockAssert.EqualError(err, "Not some error"),
|
||||||
|
"EqualError should return false for different error string")
|
||||||
|
assert.True(mockAssert.EqualError(err, "some error"),
|
||||||
|
"EqualError should return true")
|
||||||
|
}
|
||||||
|
|
||||||
func TestEmptyWrapper(t *testing.T) {
|
func TestEmptyWrapper(t *testing.T) {
|
||||||
assert := New(t)
|
assert := New(t)
|
||||||
mockAssert := New(new(testing.T))
|
mockAssert := New(new(testing.T))
|
||||||
|
|
Loading…
Reference in New Issue