I am using Dune to build a binary (not a library) whose sources all reside under the src directory. Under the directory test I have a unit test executable which depends on a module src/foo.ml. I managed to get this working by adding a custom rule that copies src/foo.ml, as shown by the file test/jbuild:
This works, but I don’t find it very satisfying. So here’s my question: is there a more elegant way to tell Dune that any modules it can’t find under test should be searched for under src?
In my opinion it would be better to just put the modules as a library, and use another directory to put the executable that depends on the library via some entry point module. That way your test could also depend on the library, preventing you from jumping hoops to make the modules available.
In my opinion it would be better to just put the modules as a library, and use another directory to put the executable that depends on the library via some entry point module. That way your test could also depend on the library, preventing you from jumping hoops to make the modules available.
The modules in src are all part of an executable, and though they could of course be “forced” into a library, I reckon the end result would be confusing…
OK, thanks for the suggestion! I reckon the best course of action may be indeed to create a private library and add a comment to jbuild explaining that the library exists solely for testing purposes…