testify icon indicating copy to clipboard operation
testify copied to clipboard

Fix failure message formatting for Positive and Negative asserts

Open lambdanis opened this issue 3 years ago • 5 comments

Summary

Error messages for Positive and Negative asserts are malformed, because of an extra argument (0) passed to the formatting function. This PR fixes that.

Changes

I moved error message formatting out of compareTwoValues function to its callers. That way all messages are formatted independently and correctly.

Motivation

The following test:

func TestNegative(t *testing.T) {
    assert.Negative(t, 1)
}

fails with the following output:

--- FAIL: TestNegative (0.00s)
    assertion_compare.go:360: 
                Error Trace:    test_test.go:20
                Error:          "1" is not negative%!(EXTRA int=0)
                Test:           TestNegative
                Messages:       []

Error message is suffixed with %!(EXTRA int=0), because Negative assert uses same function as other comparison asserts, and it includes error formatting.

Same bug occurs for Positive assert.

lambdanis avatar Mar 16 '21 02:03 lambdanis