runtime-arbitrary-tests

Last updated: 2019-01-14 17:42:57 +0000

Upstream URL: git clone http://chriswarbo.net/git/runtime-arbitrary-tests.git

Repo

View repository

View issue tracker

Contents of README follows


Tests for runtime-arbitrary

This is necessarily a separate module to <code>runtime-arbitrary</code> as that package must be available to <code>nix-eval</code> for these tests to work. To run the tests, use <code>cabal run</code>.

These tests are necessary as <code>runtime-arbitrary</code> does not provide any static guarantees that <code>getArbGen</code> will provide any Arbitrary instances. In fact, by default it will return an empty list!

To make it produce anything at all, we must insert the following line into our program (or into the preamble of a <code>nix-eval</code> expression):

<pre><code>mkIfCxtInstances ''Arbitrary</code></pre>

This uses template haskell to look up all instances of the <code>Arbitrary</code> typeclass available at that point, and make them available to <code>getArbGen</code>. The placement of this line is important: it will only find instances from those modules which have been imported at that point. This is why we don’t perform this step automatically in <code>runtime-arbitrary</code>: the available instances would be limited to what <code>runtime-arbitrary</code> has imported; by requiring users to insert this themselves, all of their imports will be available too.