Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failure message formatting for Positive and Negative asserts #1062

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lambdanis
Copy link

@lambdanis lambdanis commented Mar 16, 2021

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.

@mitar
Copy link

mitar commented Apr 5, 2024

I noticed this as well.

@ccoVeille
Copy link
Contributor

ccoVeille commented Apr 6, 2024

The PR was opened ages ago by @lambdanis

@mitar says the bug is still there.

And I tested it's confirmed. https://go.dev/play/p/ywAcp8bNkV4

=== RUN   TestNegative
    prog_test.go:11: 
        	Error Trace:	/tmp/sandbox1790707837/prog_test.go:11
        	Error:      	"1" is not negative%!(EXTRA int=0)
        	Test:       	TestNegative
--- FAIL: TestNegative (0.00s)
FAIL

@lambdanis: could you rebase and fix the conflicts or maybe close this PR if you are no longer interested?

I could reopen an PR if needed.

@lambdanis
Copy link
Author

Sure, I'll rebase it.

@ccoVeille
Copy link
Contributor

@lambdanis could you ?

@lambdanis
Copy link
Author

Rebased.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants