I’ve been using MDX for tests recently. Most of Eio’s tests are like this, for example:
Some benefits:
-
You don’t have to write printers for values, because you have a top-level environment with the types from the compiler.
-
This makes it easy to dump the whole output, rather than just probing a few properties.
-
The format encourages you to comment the test cases, group them under headings, etc.
-
If you change something in the code, it automatically generates a diff showing how the test output changes, and you can just choose to accept it (
dune runtest --autopromote
).
It has some problems too, though:
-
There’s no support for skipping tests on certain platforms (e.g. for Windows-only tests, or skipping IPv6 tests on platforms without that).
-
No merlin or ocp-indent support when editing the files.
-
Hard to see output-so-far if a test hangs (have to hunt around in /tmp for the output file).
-
Everything runs as byte-code, so it won’t find bugs specific to native code.