From ff9ded0d23a3311686084f7edeacb0e2a6b5b8f6 Mon Sep 17 00:00:00 2001 From: Samuel Nelson Date: Mon, 19 Jan 2015 12:45:07 -0700 Subject: [PATCH] Fixed regexp messages. Resolves #120. --- assert/assertions.go | 8 ++++---- assert/forward_assertions.go | 8 ++++---- require/forward_requirements.go | 8 ++++---- require/requirements.go | 11 ++++++----- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/assert/assertions.go b/assert/assertions.go index e7dd9dd..125e8ec 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -751,12 +751,12 @@ func matchRegexp(rx interface{}, str interface{}) bool { // assert.Regexp(t, "start...$", "it's not starting") // // Returns whether the assertion was successful (true) or not (false). -func Regexp(t TestingT, rx interface{}, str interface{}) bool { +func Regexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) bool { match := matchRegexp(rx, str) if !match { - Fail(t, "Expect \"%v\" to match \"%v\"", str, rx) + Fail(t, fmt.Sprintf("Expect \"%v\" to match \"%v\"", str, rx), msgAndArgs...) } return match @@ -768,11 +768,11 @@ func Regexp(t TestingT, rx interface{}, str interface{}) bool { // assert.NotRegexp(t, "^start", "it's not starting") // // Returns whether the assertion was successful (true) or not (false). -func NotRegexp(t TestingT, rx interface{}, str interface{}) bool { +func NotRegexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) bool { match := matchRegexp(rx, str) if match { - Fail(t, "Expect \"%v\" to NOT match \"%v\"", str, rx) + Fail(t, fmt.Sprintf("Expect \"%v\" to NOT match \"%v\"", str, rx), msgAndArgs...) } return !match diff --git a/assert/forward_assertions.go b/assert/forward_assertions.go index e2866f8..6a98848 100644 --- a/assert/forward_assertions.go +++ b/assert/forward_assertions.go @@ -237,8 +237,8 @@ func (a *Assertions) EqualError(theError error, errString string, msgAndArgs ... // assert.Regexp(t, "start...$", "it's not starting") // // Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) Regexp(rx interface{}, str interface{}) bool { - return Regexp(a.t, rx, str) +func (a *Assertions) Regexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) bool { + return Regexp(a.t, rx, str, msgAndArgs...) } // NotRegexp asserts that a specified regexp does not match a string. @@ -247,6 +247,6 @@ func (a *Assertions) Regexp(rx interface{}, str interface{}) bool { // assert.NotRegexp(t, "^start", "it's not starting") // // Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) NotRegexp(rx interface{}, str interface{}) bool { - return NotRegexp(a.t, rx, str) +func (a *Assertions) NotRegexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) bool { + return NotRegexp(a.t, rx, str, msgAndArgs...) } diff --git a/require/forward_requirements.go b/require/forward_requirements.go index d040ca5..069d419 100644 --- a/require/forward_requirements.go +++ b/require/forward_requirements.go @@ -198,14 +198,14 @@ func (a *Assertions) EqualError(theError error, errString string, msgAndArgs ... // // require.Regexp(t, regexp.MustCompile("start"), "it's starting") // require.Regexp(t, "start...$", "it's not starting") -func (a *Assertions) Regexp(rx interface{}, str interface{}) { - Regexp(a.t, rx, str) +func (a *Assertions) Regexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) { + Regexp(a.t, rx, str, msgAndArgs...) } // NotRegexp asserts that a specified regexp does not match a string. // // require.NotRegexp(t, regexp.MustCompile("starts"), "it's starting") // require.NotRegexp(t, "^start", "it's not starting") -func (a *Assertions) NotRegexp(rx interface{}, str interface{}) { - NotRegexp(a.t, rx, str) +func (a *Assertions) NotRegexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) { + NotRegexp(a.t, rx, str, msgAndArgs...) } diff --git a/require/requirements.go b/require/requirements.go index 1879a4f..ba28d55 100644 --- a/require/requirements.go +++ b/require/requirements.go @@ -1,8 +1,9 @@ package require import ( - "github.com/stretchr/testify/assert" "time" + + "github.com/stretchr/testify/assert" ) type TestingT interface { @@ -202,8 +203,8 @@ func InEpsilon(t TestingT, expected, actual interface{}, epsilon float64, msgAnd // // require.Regexp(t, regexp.MustCompile("start"), "it's starting") // require.Regexp(t, "start...$", "it's not starting") -func Regexp(t TestingT, rx interface{}, str interface{}) { - if !assert.Regexp(t, rx, str) { +func Regexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) { + if !assert.Regexp(t, rx, str, msgAndArgs...) { t.FailNow() } } @@ -212,8 +213,8 @@ func Regexp(t TestingT, rx interface{}, str interface{}) { // // require.NotRegexp(t, regexp.MustCompile("starts"), "it's starting") // require.NotRegexp(t, "^start", "it's not starting") -func NotRegexp(t TestingT, rx interface{}, str interface{}) { - if !assert.NotRegexp(t, rx, str) { +func NotRegexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) { + if !assert.NotRegexp(t, rx, str, msgAndArgs...) { t.FailNow() } }