matryer / is

Professional lightweight testing mini-framework for Go.
MIT License
1.77k stars 58 forks source link

Add a Contains method #30

Closed tommyknows closed 4 years ago

tommyknows commented 5 years ago

Hi! Watched the talk you gave on The Art of Testing and really liked it. That's why I'm trying out this package, and I really like its simplicity.

One thing though that I'm missing is a Contains method (basically this).

As there is none so far, I guess there is some other way to do it? For example, I have a function that returns [][]string, and I wanna check if some []string are in that slice, but do not wanna specify the order.

Thanks!

matryer commented 4 years ago

The current way would be to write that helper yourself in Go code. It's unlikely that this package would support [][]string (that's a pretty unusual type in my experience).

breml commented 4 years ago

I have written helpers for special cases with is myself. These helpers normally take is as an argument and then call one of the comparison methods to perform the actual check. One problem with doing so is, that in the output the filename and line number of the helper is provided in the output instead of the file and line where the helper is called in the actual test case. The testing package from the stdlib does provide a *T.Helper method, which allows to mark helper functions as such. I adopted this functionality in #33 for is.

matryer commented 4 years ago

Closing because It think the answer from @breml is good.