testify icon indicating copy to clipboard operation
testify copied to clipboard

assert: switch the diff library to go-diff

Open mitioshi opened this issue 1 year ago • 5 comments

Summary

This PR changes the diff library used in the assert package to go-diff.

Changes

the library used for diffing is replaced to go-diff/diffmatchpatch which is actively maintained and enables us to access structured diffs.

Motivation

See the parent PR for more context

difflib is no longer maintained and cannot be extended to modify the diff structure. We end up outputting whatever the library spews without being able to modify it easily. Having the access to the diff structure gives us a more fine-grained control over what we show to users. The initial motivation for this PR was to add colorized diffs to assert.Equal. Accessing the diff structure would make this task trivial

Related issues

Split from #1480 as per @dolmen's suggestion

mitioshi avatar Feb 22 '24 07:02 mitioshi

Why its not merged yet?

Softianix avatar Oct 29 '24 19:10 Softianix

late to the party but @mitioshi thanks for going down this path, complex diffs in tests in golang assertion libs could use some of TLC.

stefanpenner avatar Feb 04 '25 18:02 stefanpenner

Merge it at all costs

Softianix avatar Feb 10 '25 12:02 Softianix

From https://github.com/stretchr/testify/pull/1546#issuecomment-2647785759:

Merge it at all costs

@Devourian I consider this to be abusive because not respectful of the benevolent work of maintainers who will have to endure the consequences of a such change.

dolmen avatar May 25 '25 07:05 dolmen

Our preference goes to #1708 which imports the frozen difflib into this module: there is a lower risk of regressions.

However, an alternative way would be to provide a mean for the user to plug his chosen alternate difflib, without having that dependency linked (via go.mod) in Testify itself. See how this is done for YAML in #1579.

dolmen avatar Jun 02 '25 15:06 dolmen