Recursive output poorly reported
- Dominant language
- Go
- Stars
- 4.7k
- Forks
- 243
- PR merge metrics
- No merged PRs in 30d
Description
We have a case where we have a linked datastructure pointing to both children and parent nodes. Due to a bug in our test implementation we were getting a result that seems like a false-positive, but in fact `cmp` hides the actual difference under `ref#0`. This occurrs because the data structure has the same values, but different pointer addresses. See the simplified example input and output below:
```go
func Test_demo(t *testing.T) {
type node struct {
parent *node
child *node
}
t2 := &node{}
t1 := &node{child: t2}
t2.parent = t1
t3 := &node{child: t2}
t2.parent = t3
if diff := cmp.Diff(t1, t3, cmp.AllowUnexported(node{})); diff != "" {
t.Errorf("node mismatch (-want +got):\n%s", diff)
}
}
```
which produces the following output:
```
demo_test.go:20: node mismatch (-want +got):
&⟪ref#0⟫demo.node{
parent: nil,
child: &demo.node{
- parent: &⟪ref#0: 0x0140004009b0⟫(...),
+ parent: &⟪ref#0: 0x0140004009b0⟫(...),
child: nil,
},
}
```
The example code is obviously flawed, but in our case that was hidden among 100 other lines before it was distilled to these lines
Contributor guide
Assessment
This issue has not been assessed yet.