testify
testify copied to clipboard
Inconsistent Formatting between Equal/NotEqual and Less/Greater/LessOrEqual/GreaterOrEqual
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
EqualandLessdisplay errors differently.- There seems to be no difference between the
XXXandXXXffunctions 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:
TestLessshould not output a trace from the Testify Library, i.e.assertion_compare.go:230TestLessshould format the output correctly, at least in theassert.Lessfcase.- 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")
}
I believe this issue is now fixed (by https://github.com/stretchr/testify/pull/1026 and https://github.com/stretchr/testify/pull/1150), so can be closed.