3

I have a project and there is a ./tests directory at its root containing several hundred MB of data that is used by the tests of several libraries:

./tests
./src/lib1/dune
./src/lib1/tests/dune
./src/lib1/tests/tests.ml
./src/lib2/dune
./src/lib2/tests/dune
./src/lib2/tests/tests.ml
...

I also defined tests that use the data in ./tests for each library like this:

(rule
 (alias runtest)
 (action (run ./tests/tests.exe)))

I now have to somehow communicate the location of the test data to each of my tests.exe. What is the most elegant way of doing this using dune?

It seems that dune copies my test data into _build which is unnecessary because the data never changes and it doesn't make sense to waste several hundred MB of space that way. From the documentation it seems that %{project_root} would contain the path to my source files but unfortunately, the variable evaluates to . which is useless for the tests which are run after a cd _build/default/src/libX and thus . does not point to the project root anymore. So is there a dune-way to specify the path to the original source directory without ugly hacks?

Right now, I'm using an environment variable containing the full path before I run dune runtest but is there a more integrated way?

glennsl
  • 28,186
  • 12
  • 57
  • 75
josch
  • 6,716
  • 3
  • 41
  • 49

1 Answers1

0

I have not tried it myself but it sounds like the data_only_dirs stanza is what you are looking for: https://dune.readthedocs.io/en/stable/dune-files.html#data-only-dirs-since-1-6

ghilesZ
  • 1,502
  • 1
  • 18
  • 30
  • 1
    But how will my scripts know where the data directory is located? I somehow have to pass that information to them when dune runs them. – josch Dec 30 '20 at 12:53