[Haskell-cafe] How to selectively export internal entities from a
module for testing?
Thorkil Naur
naur at post11.tele.dk
Thu May 24 10:38:48 EDT 2007
Hello,
It is common practice to export only selected entities from a Haskell module
and refrain from exporting other entities so that they are only available for
internal use. There are many reasons for wanting to do this, such as reducing
the number of importable entities, avoiding the exposure of internal details
that may therefore more easily be changed, and to enable certain
optimizations (http://haskell.org/haskellwiki/Performance/Modules).
However, for one particular use, namely automated testing, it often seems
useful, even necessary, to allow even entities considered internal to be
exported: If internal entities cannot be imported by the testing code, they
can only be tested indirectly, via the exported entities, and that may turn
out to be troublesome. A possibility would be to include the testing code in
the module itself, but that seems clumsy and wasteful.
For possible guidance, I have looked at
http://darcs.haskell.org/packages/filepath and System/FilePath/Internal.hs
contains
> -- Note: leave this section to enable some of the tests to work
> #ifdef TESTING
> -- * Drive methods
> splitDrive, joinDrive,
> takeDrive, replaceDrive, hasDrive, dropDrive, isDrive,
> #endif
precisely to allow automated testing. And that, of course, solves the problem.
But I am wondering whether other solutions to this problem could be found,
perhaps even solutions that stay within the limits of the Haskell language
itself? If anybody know of alternative solutions, I would very much like to
hear about them.
Thanks and best regards
Thorkil
More information about the Haskell-Cafe
mailing list