google / go-cmp

Package for comparing Go values in tests
BSD 3-Clause "New" or "Revised" License
4.17k stars 209 forks source link

question: have diff output ignore additions #318

Open dprotaso opened 1 year ago

dprotaso commented 1 year ago

From https://github.com/google/go-cmp/blob/v0.5.9/cmp/compare.go#L113

Diff returns a human-readable report of the differences between two values: // y - x. ... func Diff(x, y interface{}, opts ...Option)

Is there a way to ignore things added iny in the output? I realize I could post process the diff output and drop lines with + but without the preceeding - but wondering if there's a better way.

dsnet commented 1 year ago

Not really. The behavior of cmp.Diff is to be symmetric such that the result of cmp.Equal(x, y) and cmp.Equal(y, x) are identical.

Functionally ignoring insertions implies an assymetric comparison, which is not something this package supports. Doing so would need to carefully think through the implications and how an asymmetric comparison would interact with existing cmp.Options that assume symmetric properties of equality.

mrwormhole commented 1 year ago

@dsnet why is it renamed as x and y? I know many people do mistakes due to this, can't it be just got and want like in the shared example?