google/go-cmp

Provide Diff statistics

shibumi opened this issue · 1 comments

Hey there,

we have a Google internal Use case, where it would be nice to support Diff statistics. Any chance that we can get this into go-cmp?

I thought about something like:

  • Total: Total number of Differences (each line counts as a difference)
  • Additions: Number of additions
  • Changes: Number of Changes
  • Removals: Number of Removals

As first draft a total number is sufficient.

dsnet commented

This is highly specialized and I don't think there needs to be first-class support for it in cmp.

You can accomplish this yourself using a custom Reporter.

The output of Diff is implemented in terms of a Reporter. You can look at the implementation in the cmp package and take the relevant parts to gather the statistics you care about.