Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QuickCheck catch-22

I'm working on a Haskell project and I started out by organizing it like this:

  • blah.hs holds the majority of the code
  • blah_main.hs has the main program
  • and blah_test.hs has the test cases.

The problem with this is that restricting the functions exported by blah.hs means restricting the functions that can be tested from blah_test.hs. Is there a good way around this issue? Because I'd really like to write test code for some of the "internal" functions that aren't being exported by blah.hs.

Thanks, Lee

like image 568
LOS Avatar asked Jun 05 '11 04:06

LOS


2 Answers

Move internal functions from the Blah.* modules to Blah.Internal.* . You can hide internal modules from the users of your library by listing them in the other-modules field in the blah.cabal file (instead of exposed-modules, where you list all modules visible to the users). Look at Hakyll's .cabal file for an example.

like image 90
Mikhail Glushenkov Avatar answered Oct 14 '22 00:10

Mikhail Glushenkov


I agree with Mikhail over all, but in some circumstances it's not really possible to make such a split. In those cases, I would recommend using the CPP (C Pre-Processor) extension, along the lines of:

module Blah
    ( public
#if TEST
    , private
#endif
    ) where
like image 20
Michael Snoyman Avatar answered Oct 13 '22 23:10

Michael Snoyman