Closed ag-eitilt closed 5 years ago
Oh man, this is great! Yeah, I was kicking myself over both of those issues and have been meaning to finish the test suite in this manner. Also, yeah, unfortunately Arrow/Category are paper generators and it's hard to actually test concrete values of them, without some unsafe hacks.
Thanks so much!
Btw, it wasn't the monad instance. It was the MonadPlus instance. some bad copy/pasting had left the tcName as "Monad" instead of "MonadPlus".
No problem! I've been relying on hedgehog-classes to kickstart the test suites for my own projects, and didn't want to wind up with too twisty a chain of #if MIN_VERSION-hedgehog-classes
directives, so figured I'd just take the time to be sure things were reasonably stable continuing on.
Like you were saying in #12, there's nothing horrible about unsafe hacks in the test code if you're careful, and as you've seen the TestIO does definitely make use of them; just need to figure out how to extend that to the other two. Glad you found the copy-paste! I was having some slight trouble tracing the code. That solves the exception in lawsIO
as well as plusLawsIO
?
lawsIO does not encounter an exception, plusLawsIO still does. But, this is expected, since the monad plus laws require:
mzero >>= f = mzero
v >> mzero = mzero
and, mzero is failIO "mzero"
, which raises a user error exception.
Note that MonadPlus has these laws, but Alternative does not test these two (since we're not necessarily in a Monad), so the alternative laws work just fine
BTW i just did a release to 0.2.2 that contains the correctness fixes for storable and the improved test suite
Ah, yeah, I must have been looking at the wrong surroundings when figuring out the error message, sorry! It did seem a bit strange that Monad would have been complaining about something from MonadPlus, but not have any problems with MonadIO. And thanks for the release!
Edit: Ah, I see what you were talking about with the copy-paste. The rest of this still holds.
After the issues with
Ord
andStorable
, it seemed like a good idea to be sure there weren't any other bugs in the tests themselves, and that can't really be done with a half-null test suite. Good news is, those seem to be the only problems! At least, unless something's hiding inArrow
orCategory
...I wound up splitting some of the laws lists (see, eg.,
Semigroup.hs
) on the basis that the sublaws shouldn't be mashed into the overriding ones, leaving their top-leveltest*Laws
empty, but it does seem like a bit of an unwieldy layout with the output being divided by both law category and instance type. In my mind, the best would be to have a single group fortestShowLaws
, say, containing one list ofconcat [lawsE, lawsInt*, lawsWord*]
, but as there's not any way to specify a prefix for the individual laws themselves, having a big block of identical "Commutative Monoid: passed" statements doesn't help anything. Regardless, I see thelaws*
lists as being in this case more for if one of them needs testing with multiple generators in the future than for testing different sets of laws.