smarty / assertions

Fluent assertion-style functions used by goconvey and gunit. Can also be used in any test or application.
Other
100 stars 34 forks source link

Should*Contain doesn't handle nested lists #13

Closed jdeveloperw closed 7 years ago

jdeveloperw commented 8 years ago

First off, thank you so much for building goconvey. It's truly a pleasure to use, and I find myself thinking much more clearly when I'm writing tests.

One use case I've had is asserting a list of list should contains a list; for example

So([][]int{[]int{1}, []int{2}, []int{3}}, ShouldContain, []int{2})

When I make the assertion, I get a panic:

panic: oglematchers.Equals: non-nil slice [recovered]
        panic: oglematchers.Equals: non-nil slice

goroutine 22 [running]:
testing.tRunner.func1(0xc820098630)
        /usr/local/Cellar/go/1.5.1/libexec/src/testing/testing.go:450 +0x171
github.com/smartystreets/assertions/internal/oglematchers.Equals(0x2e7d80, 0xc820082860, 0x0, 0x0)
        /Users/jd/go/src/github.com/smartystreets/assertions/internal/oglematchers/equals.go:68 +0x318
github.com/smartystreets/assertions/internal/oglematchers.Contains(0x2e7d80, 0xc820082860, 0x0, 0x0)
        /Users/jd/go/src/github.com/smartystreets/assertions/internal/oglematchers/contains.go:31 +0xc5
github.com/smartystreets/assertions.ShouldContain(0x2e6d60, 0xc820082880, 0xc820071640, 0x1, 0x1, 0x0, 0x0)
        /Users/jd/go/src/github.com/smartystreets/assertions/collections.go:17 +0xcc
github.com/smartystreets/assertions.so(0x2e6d60, 0xc820082880, 0x47e940, 0xc820071640, 0x1, 0x1, 0x0, 0x0)
        /Users/jd/go/src/github.com/smartystreets/assertions/doc.go:96 +0x5a
github.com/smartystreets/assertions.TestShouldContain(0xc820098630)
        /Users/jd/go/src/github.com/smartystreets/assertions/collections_test.go:42 +0xd3e
testing.tRunner(0xc820098630, 0x5a29f0)
        /usr/local/Cellar/go/1.5.1/libexec/src/testing/testing.go:456 +0x98
created by testing.RunTests
        /usr/local/Cellar/go/1.5.1/libexec/src/testing/testing.go:561 +0x86d

goroutine 1 [chan receive]:
testing.RunTests(0x47ee50, 0x5a29c0, 0x3e, 0x3e, 0x1)
        /usr/local/Cellar/go/1.5.1/libexec/src/testing/testing.go:562 +0x8ad
testing.(*M).Run(0xc82004bef8, 0xe3186)
        /usr/local/Cellar/go/1.5.1/libexec/src/testing/testing.go:494 +0x70
main.main()
        github.com/smartystreets/assertions/_test/_testmain.go:176 +0x116

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
        /usr/local/Cellar/go/1.5.1/libexec/src/runtime/asm_amd64.s:1696 +0x1
exit status 2

I found a pretty simple fix; see PR #12.

Thanks again for building great library!

mdwhatcott commented 7 years ago

Fixed by https://github.com/smartystreets/assertions/pull/12