assert: add option to colorize diffs produced by assert.Equal
This PR add an option to colorize diffs produced by assert.Equal
Changes
In this PR, the library used for diffing was replaced to diffmatchpatch which is actively maintained and enables us to access structured diffs.
Since testify is frequently used in CI/CD pipelines or piped to non-tty buffers, I made colorized diffs controlled by the TESTIFY_COLORED_DIFF environment variable. This way testify will not break any existing pipelines while letting the user control this behavior(e.g. via setting it in the go test template like this
)
Motivation
When running tests in IDE/text editor, it's difficult to analyze the diffs produced by assert.Equal. This could be improved by making diff colorized. difflib is no longer maintained and cannot be extended to modify the diff structure, so it might be better to switch to another library: https://github.com/sergi/go-diff
The resulting diff looks like this after the suggested changes
The relevant issue: https://github.com/stretchr/testify/issues/1479
Related: #1467.
Hello @mitioshi any plan to continue your work?
Some suggestion: Maybe reverse the red and green color since the green one usually means the good one (expected value)
Cheers
Hello @mitioshi any plan to continue your work?
Some suggestion: Maybe reverse the red and green color since the green one usually means the good one (expected value)
Cheers
Aw, I didn't see the initial comments and thought this PR had been overlooked. Yes, I'll look into the suggested changes this week
@dolmen I submitted a new PR for the library change as you suggested -> https://github.com/stretchr/testify/pull/1546. Could you please review it, so we can proceed with the current PR ?