[Haskell-cafe] "doctest" for haskell -- a good project?

Paul Johnson paul at cogito.org.uk
Sat Mar 22 12:08:03 EDT 2008


Shaun Cutts wrote:
> I note that there is a unit testing framework for Haskell, but I don't 
> see any doctest module. Might this be a good project?
I once looked at doing this, but I didn't get very far.

Haddock is important here because you want to include the tests as part
of the documentation.  QuickCheck properties in particular closely
resemble a formal specification.  For a couple of examples, see my
RangedSet package and Neil Mitchel's FilePath package.  I manually
copied the RangedSet tests into the Haddock documentation, while Neil
wrote a small Haskell script to extract his tests from his documentation
automatically.  Unfortunately his script is tied to specific aspects of
his FilePath package.

Haddock does not contain a full Haskell parser, which makes it difficult
to extend in a principled way (or maybe I'm just not a good enough
programmer).  The problem is you need to have several different new
kinds of mark-up, and its not always clear what to do.

You need to support QuickCheck and HUnit.  Also possibly SmallCheck and
some other similar unit testing cum specification frameworks.  For
QuickCheck you need to have type information for the tests.  For
instance the classic specification / test of "reverse" is:

> prop_reverse xs xy = (reverse xs ++ reverse ys) == reverse (ys ++ xs)

Somewhere you need to flag that "xs" and "ys" are lists of integers.  In
the case of my RangedSets I needed to run the tests with both Integers
and Doubles.

I also looked at using the Haskell parser in the libraries, but that
doesn't capture comments.  Associating a comment with a particular
construct is not that simple either.

If you can manage this then it would be great.

Paul.



More information about the Haskell-Cafe mailing list