Update: Modified link to point to specific tag of github-api-haskell
project
Update: See follow-up post
I recently got into using doctest to run tests embedded in my Haskell code as comments. Having enjoyed using Python doctest in the past, this made me very happy.
The little toy app I’ve been working on is my GitHub client which now contains lovely tests embedded as comments, for example:
So, this is wonderful and great. I can even run my doctests using the following little bash script:
As you can see, I am an aficionado of Stack. Anyway, one useful property of this script is that it will run all doctests in all .hs
files in my src
directory.
The next step for my project was then to add a test-suite
target to my project so that my doctests run when I run stack test
. I followed the instructions on the doctest README and then ran into a problem. These instructions suggest create a new test-suite
section with main-is
referencing a test main looking something like:
Unfortunately, this requires me to do one of two things:
doctests.hs
doctests.hs
to discover all the test filesI realized that this is something that other people must’ve run into and, sure enough, I discovered doctest-discover
designed specifically to deal with this scenario. This is when things got interesting: doctest-discover
’s version constraints on base
were incompatible with any of the Stack build plans available to me. Therefore, I forked doctest-discover
and updated my project’s stack.yaml
to refer to my fork via a GitHub package location:
Thus, I am now able to reference my own hacked version of this module to implement the standard auto-discovering entry point for my doctests:
Fun!
My changes enabling use of doctest-discover
have since been merged into the main doctest-discover
repo, but this still serves as an illustration of how to use packages from Git repositories with Stack: something which is reminiscent of RubyGems and another thing that makes me happy!
Content © 2024 Richard Cook. All rights reserved.