I'm having difficulties running OUnit tests, mostly because I'm new to both dune and OUnit. dune
complains when I run dune runtest
:
File "test/dune", line 4, characters 13-14:
Error: Library "f" not found.
Hint: try: dune external-lib-deps --missing @runtest
Here's the project structure:
├── dune
├── f.ml # This is the source file.
└── test
├── dune
└── f_test.ml # This is the test.
This is dune
:
(executable
(name f))
This is test/dune
:
(test
(name f_test)
(libraries oUnit f)) ; <- `f` here causes problems.
I can see that the error appears because dune does not know about f.ml
, and hence does not know about f
in the dune file.
How can I make dune compile f.ml
in such a way that test/dune
knows about the f
library that I use in test/f_test.ml
? How can I run the unit tests properly?
One possibility is to split
f
into a private library and an executable, and then test the split library.EDIT:
For instance, the project structure could be updated to
with
dune
For the test,
test/dune
:and finally
lib/dune
With this setup, the test can be run with
dune runtest
.