Reputation: 23135
I'm developing a library in Haskell, which I hope to document in a Haddock compatible way and upload to Hackage at one point. I've read about testing using Cabal's frameworks, and also HUnit and Quickcheck, but it seems in all the tutorials I've read one makes a separate directory and puts the test cases in a separate file, importing the original file.
I understand this might be appropriate sometimes, but I also think for just short tests it's simpler to put them in the same file as the implementation. Indeed, the documentation goes with the implementation, so why not the tests?
Could someone point me to the best way to achieve this, ideally in a way that:
I know this is a bit of a vague question, even some links to some tutorials and/or code that does test cases like this would be appreciated.
Upvotes: 2
Views: 560
Reputation: 3980
(QuickCheck) test cases need to be generated at runtime, that's why each test suite has its own executable. I think you're correct that it would aid documentation, but it's runnable code - that's why we wouldn't want it polluting our library.
To be honest, the type system suits as a decent inline "test framework" - by constructively proving your code to be correct with the type system, you're going even further than test cases.
Upvotes: 0
Reputation: 550
I second danidiaz's suggestion of doctest
. I've (seen it) used in lens
and it works very well IMO—tests are just Haddock comments, so aren't even compiled unless you're running the doctest.
Upvotes: 1