GoCrest - Hamcrest-like matchers for Go
Splits up the Length, Empty and Nil matchers.
Unfortunately, for matchers that work on arrays, maps or pointers will still require the compiler to be told the type of the underlying value. E.g.
// nil pointer, actual is declared as `*string`
then.AssertThat(testing, values.actual, is.NilPtr[string]())
//[]int actual
then.AssertThat(stubTestingT, test.actual, has.Length[int](test.expected))
// map
then.AssertThat(t, map[string]bool{"hello": true}, has.MapLength[string, bool](1))
.. but vanilla Nil only works on errors and requires no boilerplate types:
then.AssertThat(stubTestingT, someError, is.Nil())
Full Changelog: https://github.com/corbym/gocrest/compare/v1.1.0...v1.1.1
Asynchronous Matching (v1.0.8 onwards):
//Reader
then.WithinFiveSeconds(t, func(eventually gocrest.TestingT) {
then.AssertThat(eventually, by.Reading(slowReader, 1024), is.EqualTo([]byte("abcdefghijklmnopqrstuv")))
})
//channels
then.Eventually(t, time.Second*5, time.Second, func(eventually gocrest.TestingT) {
then.AssertThat(eventually, by.Channelling(channel), is.EqualTo(3).Reason("should not fail"))
})
// multiple assertions
then.WithinTenSeconds(t, func(eventually gocrest.TestingT) {
then.AssertThat(eventually, by.Channelling(channel), is.EqualTo(3).Reason("should will fail"))
then.AssertThat(eventually, by.Channelling(channelTwo), is.EqualTo("11").Reason("This is will not fail"))
})
Full Changelog: https://github.com/corbym/gocrest/compare/v1.0.7...v1.0.8
v.1.1.0 - generics
Changes all the matchers to use generics instead of reflection. Some still use a bit of reflection, e.g. TypeName etc.
Other major changes:
ValueContaining has been split into StringContaining, MapContaining, MapContainingValues, MapMatchingValues, ArrayContaining and ArrayMatching.
No longer panics with unknown types, as types will fail at compile time. Some idiosyncrasies with the generic types do exist, but this is language specific;
then.AssertThat(testing, map[string]bool{"hi": true, "bye": true}, has.AllKeys[string, bool]("hi", "bye"))
See the matcher_test.go file for full usage.
Full Changelog: https://github.com/corbym/gocrest/compare/v1.08...v1.1.0
Two more matchers added:
Bugs fixed:
Added a go module as per https://blog.golang.org/migrating-to-go-modules
Added matchers:
Includes:
EqualToIgnoreWhitespace matcher added.