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

Use GoString instead of String

Open mxey opened this issue 2 years ago • 0 comments

cmp's diff output is mostly valid Go and so can be nicely used to fill in the want part of a test by running the test with an empty want and then copying from cmp's diff output.

However when cmp is printing, for example, two different time.Time values, it uses the formatting as returned by the String() method. I think it would be more useful, or should be an option, it if used the GoString() method instead. GoString() is supposed to return valid Go code, which would fit into the existing output style of cmp. For time.Time, it returns Go code to create that time value, which is more useful than the string format of the value.

mxey avatar May 23 '23 08:05 mxey