I have a given interface specification in the module.mli
file. I have to write its implementation in the module.ml
file.
module.mli
provides an abstract type
type abstract_type
I'm using OUnit to create the tests. I need to use the type's implementation in them. (for example to compare the values) One solution would be to extend the interface to contain additional functions used in the tests.
But is it possible to do such a thing without modifying the interface?
The only way to expose tests without touching the module interface would be to register the tests with some global container. If you have a module called
Tests
that provides a functionregister
, yourmodule.ml
would contain something like this:I don't recommend this approach because the
Tests
module loses control over what tests it's going to run.Instead I recommend exporting the tests, i.e. adding them to
module.mli
.Note that without depending on OUnit, you can export tests of the following type that anyone can run. Our tests look like this:
The interface is: