简体   繁体   中英

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM