Gocrest Versions Save

GoCrest - Hamcrest-like matchers for Go

v1.1.1

1 year ago

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())

What's Changed

Full Changelog: https://github.com/corbym/gocrest/compare/v1.1.0...v1.1.1

v1.0.10

1 year ago

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

v1.1.0

1 year ago

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;

    • map matchers generally need to know the type of the map key values explicitly or the compiler will complain, e.g. then.AssertThat(testing, map[string]bool{"hi": true, "bye": true}, has.AllKeys[string, bool]("hi", "bye"))
    • has.Length() is likewise pernickety about types being explicit, mainly because it works on both strings and arrays. It needs to know both the type of the array and the array/string type. Confused? me too.
    • is.LessThan and is.GreaterThan no longer work on complex types. This is because the complex types do not support the comparison operators (yet, somehow, they could be compared by reflection 🤷 )

See the matcher_test.go file for full usage.

What's Changed

New Contributors

Full Changelog: https://github.com/corbym/gocrest/compare/v1.08...v1.1.0

v1.0.5

3 years ago

Two more matchers added:

  • has.EveryElement(x1...xn) - checks if actual[i] matches corresponding expectation (x[i])
  • has.StructWithValues(map[string]*gocrest.Matcher) - checks if actual[key] matches corresponding expectation (x[key])

Bugs fixed:

https://github.com/corbym/gocrest/issues/2

v1.0.4

3 years ago

v1.0.3

6 years ago

Added matchers:

  • has.TypeName - checks if an instance has the struct name x where x is a string or a matcher
  • shortcut matchers is.True and is.False

v1.0.2

6 years ago

Includes:

  • has length panicked with nil actual Matt Corby 21/01/2018 20:48
  • godoc for AppendActual Matt Corby 21/01/2018 16:40
  • anyof and all of now carry actuals over Matt Corby 21/01/2018 16:36
  • Length matcher actual was only useful if you know the length of actual
  • not now carries the actual over.

v1.0.1

6 years ago

EqualToIgnoreWhitespace matcher added.

v1.0.0

6 years ago