sol / doctest

An implementation of Python's doctest for Haskell
http://hackage.haskell.org/package/doctest
MIT License
371 stars 72 forks source link

Where to put shared test code? #243

Open robrix opened 5 years ago

robrix commented 5 years ago

I’d like to define doctests with respect to some common Arbitrary instances & some other conveniences, but I’m not sure how best to share it between different modules. In particular, I don’t want to link my library against QuickCheck or otherwise include this testing code in it, and I would prefer to avoid defining this helper code in every module’s $setup block.

I’ve tried a couple of things, but haven’t had any luck thus far:

  1. Adding a module to my doctest component & importing it in each module’s $setup block. (It can’t find the module when I do this.)

  2. Defining a private library component in the package, linking the doctest component against it, and importing it in each module’s $setup block. (It can’t find the module when I do this, and if I use -package … as an argument to doctest then it fails outright at the start, unable to find it.)

Is there a way to add test-specific code such that it’ll be available to all of the modules, without adding it to the library itself? Either as a Haskell module or as some sort of library-wide $setup block?

quasicomputational commented 5 years ago

Doing something like using an internal library with the common code, depending on it in the test component, and then cabal-doctest to handle the nitty-gritty ought to work.

If you can't get that to work, can you stick the code up somewhere, or abstract it into a gist, to see what's going on?