Change NoError formatting.

pull/49/head
Sean Talts 2014-04-04 11:36:55 -04:00
parent 37614ac277
commit c469b75615
2 changed files with 17 additions and 11 deletions

View File

@ -196,13 +196,8 @@ func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) bool {
return success return success
} }
// Nil asserts that the specified object is nil. // isNil checks if a specified object is nil or not, without Failing.
// func isNil(object interface{}) bool {
// assert.Nil(t, err, "err should be nothing")
//
// Returns whether the assertion was successful (true) or not (false).
func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) bool {
if object == nil { if object == nil {
return true return true
} else { } else {
@ -212,7 +207,18 @@ func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) bool {
return true return true
} }
} }
return false
}
// Nil asserts that the specified object is nil.
//
// assert.Nil(t, err, "err should be nothing")
//
// Returns whether the assertion was successful (true) or not (false).
func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) bool {
if isNil(object) {
return true
}
return Fail(t, fmt.Sprintf("Expected nil, but got: %#v", object), msgAndArgs...) return Fail(t, fmt.Sprintf("Expected nil, but got: %#v", object), msgAndArgs...)
} }
@ -449,10 +455,11 @@ func WithinDuration(t TestingT, expected, actual time.Time, delta time.Duration,
// //
// Returns whether the assertion was successful (true) or not (false). // Returns whether the assertion was successful (true) or not (false).
func NoError(t TestingT, err error, msgAndArgs ...interface{}) bool { func NoError(t TestingT, err error, msgAndArgs ...interface{}) bool {
if isNil(err) {
return true
}
message := messageFromMsgAndArgs(msgAndArgs...) return Fail(t, fmt.Sprintf("No error is expected but got %v", err), msgAndArgs...)
return Nil(t, err, "No error is expected but got %v %s", err, message)
} }
// Error asserts that a function returned an error (i.e. not `nil`). // Error asserts that a function returned an error (i.e. not `nil`).

View File

@ -2,7 +2,6 @@ package suite
import ( import (
"errors" "errors"
"fmt"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"io/ioutil" "io/ioutil"
"os" "os"