google / google/go-cmp

Non-determinism: leading space characters in diff occasionally turn into non-breaking space

Open
#366 4 comments 1 reaction 0 assignees View on GitHub
Dominant language
Go
Stars
4.7k
Forks
243
PR merge metrics
No merged PRs in 30d

Description

```
go 1.22.5
github.com/google/go-cmp v0.6.0
```

I noticed that `cmp.Diff` alternates between regular and non-breaking space in +- column. One is way more likely to get regular space.

This behavior creates issues when output is compared verbatim, e.g. in [testable examples](https://go.dev/blog/examples):

```go
func ExampleCmpRepr() {
type foo struct{ B, A int }
fmt.Printf("%#v\n", cmp.Diff(foo{A: 1}, foo{A: 2}))
// Output: " testnet.foo{\n \tB: 0,\n- \tA: 1,\n+ \tA: 2,\n }\n"
}
```

It fails occasionally with the following output. Using `go test -bench=.` somehow makes it more likely to manifest.

```
--- FAIL: ExampleCmpRepr (0.00s)
got:
"\u00a0\u00a0testnet.foo{\n\u00a0\u00a0\tB: 0,\n-\u00a0\tA: 1,\n+\u00a0\tA: 2,\n\u00a0\u00a0}\n"
want:
" testnet.foo{\n \tB: 0,\n- \tA: 1,\n+ \tA: 2,\n }\n"
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.