Let me begin by saying that I'm a complete beginner in OCaml, so if I seem to have made some weird choices, I'm most likely not aware of them being a choice.
I am trying to get unit testing working in my project. After some searching I settled on qtest.lib
.
I've set up my project as follows:
$ mkdir mylib
$ cd mylib
$ dune init lib mylib
In the dune
file, I've written:
(library
(name mylib)
(inline_tests (backend qtest.lib)))
In mylib.ml
, I've put the following code:
let foo x = x + 2
(*$T foo
foo 2 = 4
*)
At this point, everything works as expected:
$ dune runtest
Info: Creating file dune-project with this contents:
| (lang dune 2.9)
inline_test_runner_mylib alias runtest
random seed: 425752161
[1 / 1] >foo>mylib.ml:4 *
[1 / 1] >foo>;32;1mSUCCESS
The issues start if I try to introduce another file into the project. I created helper.ml
with the following contents:
let bar x = 3 * x
(*$T bar
bar 3 = 9
*)
Now, dune runtest
errors out with
$ dune runtest
File "mylib.ml", line 11, characters 5-11:
Error: Unbound module Helper
In some of my other attempts at reproducing it, the file mentioned was instead _build/default/.mylib.inline-tests/inline_test_runner_mylib.ml-gen
.
I first assumed that this means I'm organizing my files incorrectly. However, I can access Helper.bar
within mylib.ml
:
$ cat mylib.ml
let foo x = Helper.bar (x + 2)
$ dune build # no errors
Thus I have no idea what the problem could be here. What's going on?