From c469b756151baab2425a4c6c8680790033c79342 Mon Sep 17 00:00:00 2001 From: Sean Talts Date: Fri, 4 Apr 2014 11:36:55 -0400 Subject: [PATCH] Change NoError formatting. --- assert/assertions.go | 27 +++++++++++++++++---------- suite/suite_test.go | 1 - 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/assert/assertions.go b/assert/assertions.go index c784e1b..cc264fa 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -196,13 +196,8 @@ func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) bool { return success } -// 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 { - +// isNil checks if a specified object is nil or not, without Failing. +func isNil(object interface{}) bool { if object == nil { return true } else { @@ -212,7 +207,18 @@ func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) bool { 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...) } @@ -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). func NoError(t TestingT, err error, msgAndArgs ...interface{}) bool { + if isNil(err) { + return true + } - message := messageFromMsgAndArgs(msgAndArgs...) - return Nil(t, err, "No error is expected but got %v %s", err, message) - + return Fail(t, fmt.Sprintf("No error is expected but got %v", err), msgAndArgs...) } // Error asserts that a function returned an error (i.e. not `nil`). diff --git a/suite/suite_test.go b/suite/suite_test.go index 388421f..af01da0 100644 --- a/suite/suite_test.go +++ b/suite/suite_test.go @@ -2,7 +2,6 @@ package suite import ( "errors" - "fmt" "github.com/stretchr/testify/assert" "io/ioutil" "os"