Open pohly opened 1 year ago
My stand-alone tests were done in Go playground. The actual test above lives in a PR for Kubernetes master, which currently uses go-cmp v0.5.9.
The workaround for this is to split strings into []string at line breaks. I'm not doing that in the PR because I like the output less, but it has the necessary code commented out, just in case that it is needed.
This does seem like a bug in the reporter heuristics in how it determines what context to show. Can you provide a simple reproduction that I can run that reproduces this?
I tried to come up with a simpler reproducer, but so far without luck. I'll keep trying...
Thanks for looking into it. I tried to perform a repro with just the snippet you gave and it seemed to work properly. I could only test with the string as it appears after the transformation. I wonder if the transformer is somehow messing with the cmp
reporter logic.
Just as a sanity check, make sure you're using the latest version of cmp
. I have chased down bug reports in cmp
before that turned out to be fixed in the latest version.
It's the combination of embedding inside a struct and using a transformer which triggers it. Here's a reproducer:
Output:
The number of lines is irrelevant, it also stops doing the diff for less lines. It just chose a high number to demonstrate that the output then doesn't show the actual difference anymore.
cmp is at 0.5.9, the latest.
Sometimes I get output where the relevant difference between two strings is not shown because one or both get truncated with
elided lines
. Example:In this example, I started with the expected string set to empty, copied as much of the actual string as possible, and then repeated. But because not all of it was shown, I am missing some lines. I was hoping to get a diff with the missing lines, but the heuristics apparently decided to just show both strings.
The simplify function does some string->string replacement to get rid of some line numbers and time stamps.
It's not entirely clear to me why this happens. I tried to reproduce it with exactly these strings and without a transformer, but then it worked as expected (showed a diff). I also tried with a transformer, with the same result.