Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a proper test suite #89

Closed
treeowl opened this issue Mar 19, 2018 · 18 comments
Closed

Add a proper test suite #89

treeowl opened this issue Mar 19, 2018 · 18 comments
Labels
task Something that needs to be done (not a bug fix)

Comments

@treeowl
Copy link
Collaborator

treeowl commented Mar 19, 2018

I just went to try to add QuickCheck or SmallCheck properties to the test suite, and discovered that there isn't a proper test suite. Ack! No wonder the Foldable instance for Array managed to be wrong for so long! I'll be happy to write some properties, but I don't have the time right now to set up the framework.

@RyanGlScott
Copy link
Member

Alas, this is not as easy to accomplish as it sounds. QuickCheck in particular depends on tf-random, which in turn depends on primitive itself, so you quickly run into haskell/cabal#5200 if you try to make primitive's test suite depend on it.

That being said, there is a relatively serviceable workaround: turn the test suite into its own .cabal file and make it its own project, distinct from primitive itself. That way, build tools can first build primitive and then build tf-random et al. using the locally built primitive, avoiding any dependency cycles. I've used this hack before to make a test suite for transformers-compat, and it seems to work okay.

@RyanGlScott
Copy link
Member

I've opened #90 to implement the suggestion in #89 (comment). Once that is merged (pending Travis giving a green check mark), that should make setting up QuickCheck tests far, far easier.

@treeowl
Copy link
Collaborator Author

treeowl commented Mar 19, 2018 via email

@andrewthad
Copy link
Collaborator

@RyanGlScott Thanks for moving the test suite into its own project. I'm going to work on adding some property tests.

@treeowl
Copy link
Collaborator Author

treeowl commented Mar 20, 2018 via email

@andrewthad
Copy link
Collaborator

I'm working on it now. I'm going to use tasty + quickcheck + quickcheck-classes just as an easy way to get access to some of the typeclass property tests we're interested in.

@RyanGlScott
Copy link
Member

Thanks @andrewthad!

Do be aware that primitive has a support window back to GHC 7.4, so using quickcheck-classes in its current state would shorten that window somewhat (as it only supports GHC 7.8 and later at the moment).

@treeowl
Copy link
Collaborator Author

treeowl commented Mar 20, 2018 via email

@andrewthad
Copy link
Collaborator

@RyanGlScott Good point. Let me see if I can get quickcheck-classes to support older GHCs. I don't think there's any fundamental reason that it can't.

@treeowl treeowl added the task Something that needs to be done (not a bug fix) label Mar 20, 2018
@andrewthad
Copy link
Collaborator

It was more difficult than I expected, but I now have quickcheck-classes building with all GHCs back to 7.4. I'll get the tests together now.

@treeowl
Copy link
Collaborator Author

treeowl commented Mar 20, 2018

Huzzah! Unfortunately, quickcheck-classes is not yet really up to the job. It's missing Traversable altogether (which I have a PR to reimplement). It's also missing the foldl1 and foldr1 methods; we had some trouble with foldl1! I also don't really understand its tests. I would think the Monad laws, for instance, would be tested using Test.QuickCheck.Function, but they're not. Why not something roughly like this:

monadAssoc ::  ... => m A -> Fun A (m B) -> Fun B (m C) -> Property
monadAssoc m f g = (m >>= \x -> apply f x >>= apply g) `equivalent`
                         ((m >>= apply f) >>= apply g)

For Traversable, I suggest you consider the answers to my long-ago SO question on the topic.

@andrewthad
Copy link
Collaborator

I've got a start on it here: #99. Already, we can see that it fails the laws for Functor, which is expected.

@treeowl I agree that it's currently missing several things. I had never done Traverable since those are normally derived. I had only done Foldable (also normally easy to derive) as an exercise since the strict variants of the fold functions are tricky to test correctly. I've never used Test.QuickCheck.Function, and it's almost certainly a better way to test some of the monad properties than what I came up with.

@cartazio
Copy link
Contributor

cartazio commented Mar 20, 2018 via email

@treeowl
Copy link
Collaborator Author

treeowl commented Mar 20, 2018

For Traversable, you need to test the identity law, which should be easy, and the composition law, which will be harder. Also, like checkers, you'll want to verify that foldMapDefault and fmapDefault match foldMap and fmap. If you're adding detailed strictness checks as well (see ChasingBottoms), you'll probably want to check the naturality law too, but that sort of detail can surely wait.

@treeowl
Copy link
Collaborator Author

treeowl commented Mar 20, 2018

@cartazio, I don't see how that could help. QuickCheck has loads of dependencies. We could try a different test framework, I suppose.

@treeowl
Copy link
Collaborator Author

treeowl commented Mar 23, 2018

@andrewthad, are we ready to close this, or are there still non-trivial functions that lack adequate tests?

@andrewthad
Copy link
Collaborator

We still aren't testing the following typeclass instances: MonadZip, Alternative, MonadPlus, and MonadFix. Of those, only MonadFix has what I would describe as a trivial implementation. All the others are at least as complicated as fmap. However, I would prefer closing out this issue, since the objective "Add a proper test suite" is complete, and opening a new one instead to track progress on those.

@treeowl
Copy link
Collaborator Author

treeowl commented Mar 26, 2018

Done! I opened up an issue to track test suite expansion.

@treeowl treeowl closed this as completed Mar 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
task Something that needs to be done (not a bug fix)
Projects
None yet
Development

No branches or pull requests

4 participants