testify
testify copied to clipboard
Colorize 'expected' and 'actual'
Summary
Colorize "expected" and "actual"
Changes
Resolves #946
Motivation
-
@boyan-soubachov says "It's an interesting idea."
-
@mvdkleijn says "I like this idea."
package testify
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
func TestExamples(t *testing.T) {
wrapT := assert.WrapColorize(t)
newAssert := assert.New(wrapT)
assert.Equal(wrapT, 1, 2)
assert.Equal(wrapT, "A", "b")
newAssert.Equal(3, 4)
assert.Same(wrapT, new(assert.Colorize), new(assert.Colorize))
newAssert.Same(new(assert.Colorize), new(assert.Colorize))
assert.EqualValues(wrapT, uint32(123), int32(124))
newAssert.EqualValues(uint32(123), int32(124))
assert.EqualError(wrapT, errors.New("foo"), "bar")
newAssert.EqualError(errors.New("foo"), "bar")
}
Related issues
N/A
Screenshot
TestColorize
Equal
Same
EqualValues
EqualError
Dear @boyan-soubachov , do you mind review this PR or give some suggestion?
Can you retest by redirecting to a file and see if you see control characters ?
I think yes.
Please refer this unit test: assert/colorize_test.go#L31
func TestColorize_Message(t *testing.T) {
failureMessage := fmt.Sprintf("Not equal: \n"+
"expected: %s\n"+
"actual : %s%s", "expected", "actual", "diff")
fmt.Println(WrapColorize(t).Message(failureMessage))
}
output:

I think yes.
Please refer this unit test: assert/colorize_test.go#L31
func TestColorize_Message(t *testing.T) { failureMessage := fmt.Sprintf("Not equal: \n"+ "expected: %s\n"+ "actual : %s%s", "expected", "actual", "diff") fmt.Println(WrapColorize(t).Message(failureMessage)) }output:
I think that proves it fails - you can see the terminal escapes e.g. [31m and [0m.