Dune tests in subdirectories

Hey all,

We’re building a compiler in OCaml and setting up our project with Dune. We have many, many program files in many directories and subdirectories that we would like to create expect tests for. Currently we are putting the exact same ‘dune’ file in every subdirectory, but we’d like to see if there’s a better way. Some ways I can think of:

  1. glob_files working with subdirectories (seems not to right now)
  2. dune working with symlinks (seems not to) - we could put a symlink in each subdirectory and at least avoid problems with getting out of sync
  3. make-style patterns (showing how to generally make %.expected files, or something)

Anyone have ideas? Tagging @jeremiedimino because he’s been helping me learn dune already.

To make it concrete, here is our repo: https://github.com/stan-dev/stanc3/tree/master/test/integration

Any and all tips welcome, from minor ocaml code review on up :slight_smile:

Thanks!

You are using a top-level Makefile, so you could use it to generate the identical dune file in all test directories — if nobody comes up with a good solution within Dune. Hard linking all these dune files would be another option to keep them in sync.

1 Like

The symlinks should work at the moment. You can also use (include ../dune.common). We also started thinking about how to improve this pattern and we have a few ideas. We did a first attempt there although it didn’t feel generic enough.

We don’t have a new concrete design yet, but it’s on the todo list.

I get this error when I add a few symlinks:

halair ~/scm/stanc3/test/integration/examples-bad (master) $ dune runtest
Error: exception Sys_error("test/integration/examples-bad/algebra_solver/dune: Too many levels of symbolic links")
Backtrace:
Raised by primitive operation at file "stdlib.ml", line 390, characters 28-54
Called from file "src/stdune/io.ml", line 63, characters 17-37
Called from file "src/file_tree.ml", line 225, characters 16-110
Called from file "camlinternalLazy.ml", line 27, characters 17-27
Re-raised at file "camlinternalLazy.ml", line 34, characters 4-11
Called from file "src/file_tree.ml" (inlined), line 124, characters 20-32
Called from file "src/dune_load.ml", line 246, characters 16-41
Called from file "src/file_tree.ml", line 141, characters 16-23
Called from file "map.ml", line 319, characters 19-42
Called from file "map.ml", line 319, characters 26-41
Called from file "map.ml", line 319, characters 26-41
Called from file "map.ml", line 319, characters 19-42
Called from file "map.ml", line 319, characters 19-42
Called from file "map.ml", line 319, characters 19-42
Called from file "src/file_tree.ml" (inlined), line 286, characters 2-49
Called from file "src/dune_load.ml", line 244, characters 4-282
Called from file "src/main.ml", line 44, characters 4-68
Called from file "src/main.ml", line 277, characters 12-56
Called from file "bin/main.ml", line 134, characters 4-26
Called from file "bin/main.ml", line 149, characters 33-42
Called from file "vendor/cmdliner/src/cmdliner_term.ml", line 27, characters 19-24
Called from file "vendor/cmdliner/src/cmdliner.ml", line 106, characters 32-39
Called from file "vendor/cmdliner/src/cmdliner.ml", line 136, characters 18-36
Called from file "vendor/cmdliner/src/cmdliner.ml", line 251, characters 22-48
Called from file "bin/main.ml", line 1184, characters 10-51

I must not segfault.  Uncertainty is the mind-killer.  Exceptions are
the little-death that brings total obliteration.  I will fully express
my cases.  Execution will pass over me and through me.  And when it
has gone past, I will unwind the stack along its path.  Where the
cases are handled there will be nothing.  Only I will remain.

Woops, I was messing up my symlinks and got sidetracked by the awesome Dune reference :joy:

1 Like