go-cmp icon indicating copy to clipboard operation
go-cmp copied to clipboard

String diff for UUIDs can use strings.Join syntax which makes it more confusing

Open prashantv opened this issue 1 year ago • 4 comments

This is a similar topic as #274 and #195, but when using cmp to diff UUIDs.

When the UUIDs are very different, the output looks like:

  	ID: strings.Join({
- 		"e93d2d8b-7d2a-4c62-967a-b189347a4fa2",
+ 		"7e93c401-4e27-3b83-7edc-2dd0803c39b3",
  	}, ""),

The strings.Join adds unnecessary noise here, ideally it would be displayed as:

-  	ID: "e93d2d8b-7d2a-4c62-967a-b189347a4fa2",
+ 	ID: "7e93c401-4e27-3b83-7edc-2dd0803c39b3",

However, if the UUIDs have common characters, the output gets really verbose, and isn't particularly useful:

  	ID: strings.Join({
- 		"217d",
  		"6",
- 		"7ef-d686-4107-ab35-347ed6c91a22",
+ 		"68416ab-a20e-48ae-afaa-8df7b91a4af3",
  	}, ""),

Is there a way to avoid this specialized string handling and have it never use the strings.Join output but show a simpler remove/add for string fields?

prashantv avatar Mar 21 '24 06:03 prashantv

Thanks for filing. This is a bug. There are more differences than similarities, that it shouldn't have chosen this particular representation.

dsnet avatar Mar 21 '24 06:03 dsnet

For my own benefit, here's a reproduction: https://go.dev/play/p/7u4lcejtNsf

dsnet avatar Mar 21 '24 06:03 dsnet

Thanks for the additional context. Even in the case that the UUIDs have significant overlap, the strings.Join format is noisy, and causes other issues for code that tries to detect and replace UUIDs.

Ideally we could turn off this feature completely, is there existing options that can be passed to control this behaviour?

prashantv avatar Mar 29 '24 14:03 prashantv

Looks like this was introduced in 0.5.6. Works correctly in 0.5.5.

richunger avatar Jun 11 '24 18:06 richunger