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 function register
, your module.ml
would contain something like this:
let some_test = ...
let () = Tests.register some_test
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:
let test_cool_feature () =
...
assert ...;
...
assert ...;
true
let test_super_feature () =
...
a = b
let tests = [
"cool feature", test_cool_feature;
"super feature", test_super_feature;
]
The interface is:
...
(**/**)
(* begin section ignored by ocamldoc *)
val test_cool_feature : unit -> bool
val test_super_feature : unit -> bool
val tests : (string * (unit -> bool)) list