Skip to content

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

@mejedi

Description

@mejedi
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:

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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions