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

Inconsistent Formatting between Equal/NotEqual and Less/Greater/LessOrEqual/GreaterOrEqual #1034

Open
cheinani2x opened this issue Dec 24, 2020 · 1 comment

Comments

@cheinani2x
Copy link

cheinani2x commented Dec 24, 2020

Edit: It looks like there are two PRs already open to fix this issue.

For the sake of brevity, I will reduce this example to Equal and Less, but Equal and NotEqual behave the same and Greater, Less, GreaterOrEqual and LessOrEqual behave the same; however, I wrote a full example on the Go Playground. I see the same behavior in my code and in the Go playground.

I am reporting against version 1.6.1 running Go 1.14.

The issues are

  1. Equal and Less display errors differently.
  2. There seems to be no difference between the XXX and XXXf functions and the docs are unclear about any differences.

Code:

package main

import (
	"github.com/stretchr/testify/assert"
	"testing"
)

func TestLess(t *testing.T) {
	assert.Less(t, 3, 2, "Message %s-%d", "42", 42)
	assert.Lessf(t, 3, 2, "Message %s-%d", "42", 42)
}

func TestEqual(t *testing.T) {
	assert.Equal(t, 1, 2, "Message %s-%d", "42", 42)
	assert.Equalf(t, 1, 2, "Message %s-%d", "42", 42)
}
Actual Output:
=== RUN   TestLess
    assertion_compare.go:230: 
        	Error Trace:	prog.go:9
        	Error:      	"3" is not less than "2"
        	Test:       	TestLess
        	Messages:   	[Message %s-%d 42 42]
    assertion_compare.go:230: 
        	Error Trace:	prog.go:10
        	Error:      	"3" is not less than "2"
        	Test:       	TestLess
        	Messages:   	[Message %s-%d 42 42]
--- FAIL: TestLess (0.00s)
=== RUN   TestEqual
    prog.go:14: 
        	Error Trace:	prog.go:14
        	Error:      	Not equal: 
        	            	expected: 1
        	            	actual  : 2
        	Test:       	TestEqual
        	Messages:   	Message 42-42
    prog.go:15: 
        	Error Trace:	prog.go:15
        	Error:      	Not equal: 
        	            	expected: 1
        	            	actual  : 2
        	Test:       	TestEqual
        	Messages:   	Message 42-42
--- FAIL: TestEqual (0.00s)
FAIL

2 tests failed.

Expected Output:

  • TestLess should not output a trace from the Testify Library, i.e. assertion_compare.go:230
  • TestLess should format the output correctly, at least in the assert.Lessf case.
  • The docs should explain what the non-formatted function additional arguments do.

I tried the documentation example as well and it failed the same way.

func TestDocExamples(t *testing.T) {
	assert.Lessf(t, 3, 2, "error message %s", "formatted")
	assert.Lessf(t, float64(3), float64(2), "error message %s", "formatted")
	assert.Lessf(t, "c", "b", "error message %s", "formatted")
}
@lambdanis
Copy link

I believe this issue is now fixed (by #1026 and #1150), so can be closed.

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

No branches or pull requests

2 participants