testify icon indicating copy to clipboard operation
testify copied to clipboard

export `includeElement`

Open falsaffa opened this issue 3 years ago • 2 comments

Summary

The assertion package is useful for non-test assertions using things such as assert.ObjectsAreEqualValues. Similarly it would be useful to export the assert.includeElement function that is used by assert.Contains to be used in a non test environment.

falsaffa avatar Mar 19 '22 19:03 falsaffa

That's a very inefficient Contains function to use on a known type, I don't think it's use outside of tests should be encouraged. Have you considered using https://pkg.go.dev/golang.org/x/exp/slices#Contains ?

brackendawson avatar Mar 20 '22 16:03 brackendawson

Ahhh generics, good call. Thank you!

On a separate item, includeElement is also within tests. Sometimes a mock function processing a call needs to perform different assertions based on whether or not a particular item is in an array (and the array is of type []interface{}) such as args passed to a sql.Exec(query, args...) call. There is still a use within tests.

falsaffa avatar Mar 20 '22 16:03 falsaffa

The slices package will appear in stdlib with Go 1.21 with a Contains function. So I expect that the need described here will disappear.

Anyway, as a general rule, I think that using testify beyond a testing context is out of scope for this project. If some functions of testify are useful outside a testing context they must be extracted into a separate project. testify is for testing.

dolmen avatar Jul 07 '23 08:07 dolmen