frankban / quicktest

Quick helpers for testing Go applications
MIT License
529 stars 27 forks source link

Not(DeepEquals) succeeds even though go-cmp panicked #153

Closed lmb closed 1 year ago

lmb commented 1 year ago

The following test cases succeeds somewhat surprisingly:

func TestNotDeepEquals(t *testing.T) {
    type a struct {
        v int
    }

    v1 := a{1}
    qt.Assert(t, v1, qt.Not(qt.DeepEquals), v1)
}

Dropping the Not reveals that go-cmp actually returned an error:

        error:
          cannot handle unexported field at {testutils.a}.v:
            "github.com/cilium/ebpf/internal/testutils".a
          consider using a custom Comparer; if you control the implementation of type, you can also consider using an Exporter, AllowUnexported, or cmpopts.IgnoreUnexported
        got:
          testutils.a{v:1}
        want:
          <same as "got">
        stack:
          /home/lorenz/dev/ebpf/internal/testutils/cmp_test.go:15
            qt.Assert(t, v1, qt.DeepEquals, v1)

Seems like Not treats an error from the checker which means "wasn't able to compare" the same as "not equal".

frankban commented 1 year ago

Released as v1.14.5