Skip to content

Commit

Permalink
Fix failure message formatting for Positive and Negative asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
Ania Kapuścińska committed Mar 16, 2021
1 parent 6990a05 commit f82b5cb
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions assert/assertion_compare.go
Expand Up @@ -313,7 +313,8 @@ func Greater(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface
if h, ok := t.(tHelper); ok {
h.Helper()
}
return compareTwoValues(t, e1, e2, []CompareType{compareGreater}, "\"%v\" is not greater than \"%v\"", msgAndArgs)
failMessage := fmt.Sprintf("\"%v\" is not greater than \"%v\"", e1, e2)
return compareTwoValues(t, e1, e2, []CompareType{compareGreater}, failMessage, msgAndArgs)
}

// GreaterOrEqual asserts that the first element is greater than or equal to the second
Expand All @@ -326,7 +327,8 @@ func GreaterOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...in
if h, ok := t.(tHelper); ok {
h.Helper()
}
return compareTwoValues(t, e1, e2, []CompareType{compareGreater, compareEqual}, "\"%v\" is not greater than or equal to \"%v\"", msgAndArgs)
failMessage := fmt.Sprintf("\"%v\" is not greater than or equal to \"%v\"", e1, e2)
return compareTwoValues(t, e1, e2, []CompareType{compareGreater, compareEqual}, failMessage, msgAndArgs)
}

// Less asserts that the first element is less than the second
Expand All @@ -338,7 +340,8 @@ func Less(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{})
if h, ok := t.(tHelper); ok {
h.Helper()
}
return compareTwoValues(t, e1, e2, []CompareType{compareLess}, "\"%v\" is not less than \"%v\"", msgAndArgs)
failMessage := fmt.Sprintf("\"%v\" is not less than \"%v\"", e1, e2)
return compareTwoValues(t, e1, e2, []CompareType{compareLess}, failMessage, msgAndArgs)
}

// LessOrEqual asserts that the first element is less than or equal to the second
Expand All @@ -351,7 +354,8 @@ func LessOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...inter
if h, ok := t.(tHelper); ok {
h.Helper()
}
return compareTwoValues(t, e1, e2, []CompareType{compareLess, compareEqual}, "\"%v\" is not less than or equal to \"%v\"", msgAndArgs)
failMessage := fmt.Sprintf("\"%v\" is not less than or equal to \"%v\"", e1, e2)
return compareTwoValues(t, e1, e2, []CompareType{compareLess, compareEqual}, failMessage, msgAndArgs)
}

// Positive asserts that the specified element is positive
Expand All @@ -363,7 +367,8 @@ func Positive(t TestingT, e interface{}, msgAndArgs ...interface{}) bool {
h.Helper()
}
zero := reflect.Zero(reflect.TypeOf(e))
return compareTwoValues(t, e, zero.Interface(), []CompareType{compareGreater}, "\"%v\" is not positive", msgAndArgs)
failMessage := fmt.Sprintf("\"%v\" is not positive", e)
return compareTwoValues(t, e, zero.Interface(), []CompareType{compareGreater}, failMessage, msgAndArgs)
}

// Negative asserts that the specified element is negative
Expand All @@ -375,7 +380,8 @@ func Negative(t TestingT, e interface{}, msgAndArgs ...interface{}) bool {
h.Helper()
}
zero := reflect.Zero(reflect.TypeOf(e))
return compareTwoValues(t, e, zero.Interface(), []CompareType{compareLess}, "\"%v\" is not negative", msgAndArgs)
failMessage := fmt.Sprintf("\"%v\" is not negative", e)
return compareTwoValues(t, e, zero.Interface(), []CompareType{compareLess}, failMessage, msgAndArgs)
}

func compareTwoValues(t TestingT, e1 interface{}, e2 interface{}, allowedComparesResults []CompareType, failMessage string, msgAndArgs ...interface{}) bool {
Expand All @@ -395,7 +401,7 @@ func compareTwoValues(t TestingT, e1 interface{}, e2 interface{}, allowedCompare
}

if !containsValue(allowedComparesResults, compareResult) {
return Fail(t, fmt.Sprintf(failMessage, e1, e2), msgAndArgs...)
return Fail(t, failMessage, msgAndArgs...)
}

return true
Expand Down

0 comments on commit f82b5cb

Please sign in to comment.