gotest.tools icon indicating copy to clipboard operation
gotest.tools copied to clipboard

Add complete property assertion

Open dnephin opened this issue 2 years ago • 0 comments

This PR adds a new function for property testing of operations that need to include all the fields on a struct. Common examples of functions that could be tested with Complete include:

  • any Equal method
  • any IsEmpty or IsZero method
  • any function that builds a hash or map key from a structs fields

In all of these cases, adding a new field to the struct will break the operation unless the function is updated to include the new field. This addition can be easy to miss. If the function has a test that uses Complete, any contributor would get a clear test failure that they've forgotten to consider the new field in some operation.

This implementation uses generics, which makes it a bit easier to validate the inputs. I had a previous version that used reflection to validate the inputs, but it was a lot more involved. Since it uses generics we won't be able to include this package in the main Go module until we drop support for Go 1.17. For now the new package is added under x/generics which is a separate Go module.

dnephin avatar May 08 '22 19:05 dnephin