Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running OUnit tests using dune

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?

like image 817
Flux Avatar asked Nov 15 '18 10:11

Flux


1 Answers

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

├── dune
├── f.ml  # f only contains the I/O glue code.
├── lib
|    ├── dune
|    └── a.ml  # a implements the features that need to be tested.
└── test
    ├── dune
    └── test.ml  # This is the test.

with dune

 (executable (name main) (libraries Lib)) 

For the test, test/dune:

(test (name test) (libraries Lib oUnit))

and finally lib/dune

(library (name Lib))

With this setup, the test can be run with dune runtest.

like image 161
octachron Avatar answered Oct 10 '22 14:10

octachron