Closed anacrolix closed 4 years ago
It seems that the check is doing what you want (e"unexpected EOF" is not e"EOF"), and the only confusing part is that the container is called "got" when qt.Contains is used. See https://play.golang.org/p/oHVE-hZOJXL
Perhaps we should just rename the argument name at https://play.golang.org/p/oHVE-hZOJXL ?
Hm I'm not sure. It's definitely only the argument name that is confusing. Isn't it possible to write a checker that is Any the other way around?
Maybe something like IsIn.
We try not to have two different ways of doing the same check in quicktest itself, but a nice feature of the library is that anyone can write their own checkers to use with qt.Assert or qt.Check fairly easily.
That's fair, it seems pretty common. Perhaps a checker that allows you to reverse the arguments? That might fix many such instances in one go.
Here's the code I'm hoping to move to quicktest, if you're curious: https://github.com/anacrolix/torrent/blob/7fe199992c7efabba3ce947902e41382bff33bf1/storage/file_test.go#L37-L43.
If you don't want to define your own checker, and if you don't want to just use qt.Assert([]error{nil, io.EOF}, qt.Contains, err)
, there is an expressive alternative using qt.Satisfies
, like:
func isNilOrEOF(err error) bool {
return err == nil || err == io.EOF
}
c.Assert(err, qt.Satisfies, isNilOrEOF)
I have the following check:
c.Check(err, qt.Any(qt.Equals), []error{nil, io.EOF})
I rushed into this assuming that it would test that it would pass if
err
matched any ofnil
andio.EOF
. After reading the documentation I see that I got the operands reversed, but if I reverse them, the failure message is:Which suggests that
[]error{nil, io.EOF}
is expected to matcherr
.How can I check that
err
matches one of a list of values with the builtin checkers?