godebug icon indicating copy to clipboard operation
godebug copied to clipboard

Add support for fmt.GoStringer interface

Open 2opremio opened this issue 5 years ago • 1 comments

Apart from fmt.Stringer, it would be good if fmt.GoStringer was supported

I think GoStringer should (at least by default) have higher priority than fmt.Stringer

2opremio avatar Aug 27 '20 18:08 2opremio

Thanks for the request. It's certainly probable that it should have been, but I am very reluctant to add something like this that will change the behavior for existing code, as (for better or worse) some users of this library have hard-coded the expected output of Print instead of comparing against a golden value with Diff. Adding a config flag is certainly an option, but I am also reluctant to add configuration for things that can be accommodated with existing configs.

For anyone who comes across this, my recommended current approach is to use config.Formatter to opt-in to GoString for the types you require.

I will tag this as a potential feature for v2, in case we do wind up with enough breaking changes to require one.

Also, check out package cmp. I generally think it does the job better and is already more featureful than pretty.

kylelemons avatar Aug 30 '20 17:08 kylelemons