-
Notifications
You must be signed in to change notification settings - Fork 210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
string difference not visible due to "elided lines" #311
Comments
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 Just as a sanity check, make sure you're using the latest version of |
It's the combination of embedding inside a struct and using a transformer which triggers it. Here's a reproducer: package main
import (
"fmt"
"strings"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/onsi/ginkgo/v2/reporters"
)
func main() {
expected := strings.Repeat("hello\n", 50)
actual := expected + "world\n"
// Works.
// fmt.Println(cmp.Diff(expected, actual,
// cmpopts.AcyclicTransformer("simplify", func(in string) string {
// return in
// }),
// ))
expectedSuite := reporters.JUnitTestSuite{
TestCases: []reporters.JUnitTestCase{
{
Name: "[It] e2e works",
SystemErr: expected,
},
},
}
actualSuite := reporters.JUnitTestSuite{
TestCases: []reporters.JUnitTestCase{
{
Name: "[It] e2e works",
SystemErr: actual,
},
},
}
// Works.
// fmt.Println(cmp.Diff(expectedSuite, actualSuite))
fmt.Println(cmp.Diff(expectedSuite, actualSuite,
cmpopts.AcyclicTransformer("simplify", func(in string) string {
return in
}),
))
} 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.
The text was updated successfully, but these errors were encountered: