From 7e30b2ce7a60520f96878ac671d25086dbe1e96b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ernesto=20Jime=CC=81nez?= Date: Fri, 8 Jan 2016 12:25:24 +0100 Subject: [PATCH] Fixes #261 - Add FailNow back --- assert/assertion_forward.go | 6 ++++++ assert/assertions.go | 8 ++++++++ mock/mock.go | 1 + require/require.go | 8 ++++++++ require/require_forward.go | 6 ++++++ 5 files changed, 29 insertions(+) diff --git a/assert/assertion_forward.go b/assert/assertion_forward.go index ed5b84e..e6a7960 100644 --- a/assert/assertion_forward.go +++ b/assert/assertion_forward.go @@ -107,6 +107,12 @@ func (a *Assertions) Fail(failureMessage string, msgAndArgs ...interface{}) bool } +// FailNow fails test +func (a *Assertions) FailNow(failureMessage string, msgAndArgs ...interface{}) bool { + return FailNow(a.t, failureMessage, msgAndArgs...) +} + + // False asserts that the specified value is false. // // a.False(myBool, "myBool should be false") diff --git a/assert/assertions.go b/assert/assertions.go index 960bc1c..e5c5e5c 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -21,6 +21,7 @@ import ( // TestingT is an interface wrapper around *testing.T type TestingT interface { Errorf(format string, args ...interface{}) + FailNow() } // Comparison a custom function that returns true on success and false on failure @@ -181,6 +182,13 @@ func indentMessageLines(message string, tabs int) string { return outBuf.String() } +// FailNow fails test +func FailNow(t TestingT, failureMessage string, msgAndArgs ...interface{}) bool { + Fail(t, failureMessage, msgAndArgs...) + t.FailNow() + return false +} + // Fail reports a failure through func Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) bool { diff --git a/mock/mock.go b/mock/mock.go index bc6c86b..a664252 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -17,6 +17,7 @@ import ( type TestingT interface { Logf(format string, args ...interface{}) Errorf(format string, args ...interface{}) + FailNow() } /* diff --git a/require/require.go b/require/require.go index 0cd0fde..1bcfcb0 100644 --- a/require/require.go +++ b/require/require.go @@ -126,6 +126,14 @@ func Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) { } +// FailNow fails test +func FailNow(t TestingT, failureMessage string, msgAndArgs ...interface{}) { + if !assert.FailNow(t, failureMessage, msgAndArgs...) { + t.FailNow() + } +} + + // False asserts that the specified value is false. // // assert.False(t, myBool, "myBool should be false") diff --git a/require/require_forward.go b/require/require_forward.go index 5f72cec..58324f1 100644 --- a/require/require_forward.go +++ b/require/require_forward.go @@ -108,6 +108,12 @@ func (a *Assertions) Fail(failureMessage string, msgAndArgs ...interface{}) { } +// FailNow fails test +func (a *Assertions) FailNow(failureMessage string, msgAndArgs ...interface{}) { + FailNow(a.t, failureMessage, msgAndArgs...) +} + + // False asserts that the specified value is false. // // a.False(myBool, "myBool should be false")