Dune test error: 'Fatal error: exception Sys_error("data/abs.decTest: No such file or directory")'

Hi, running dune test in CI ( https://opam.ci.ocaml.org/github/ocaml/opam-repository/commit/22cd4fd03c1642202eb2f4c2097c190285b9e91c/variant/compilers,4.08,decimal.0.1.0,tests ) is failing with the following output:

### output ###
# decimal_test alias test/runtest (exit 2)
# (cd _build/default/test && ./decimal_test.exe)
# Test file: data/abs.decTest
# Fatal error: exception Sys_error("data/abs.decTest: No such file or directory")

The line Test file: data/abs.decTest is printed from the following code in decimal_test.ml:

let eval_file filename =
  print_string "Test file: ";
  print_endline filename;
  let ch = open_in filename in
  let str = really_input_string ch (in_channel_length ch) in
  close_in ch;
  eval_str str

So it’s throwing the exception when trying to open the file data/abs.decTest. Thing is, the file (among others) does exist in the repo:


I know that dune does the build in an internal working directory, do I need to somehow tell it to copy the test data files into that and if so how? Would that be with https://dune.readthedocs.io/en/stable/dune-files.html?highlight=copy#copy-files ?

1 Like

You should tell Dune that those files are a dependency of your tests:

diff --git a/test/dune b/test/dune
index f4745b3..660ae37 100644
--- a/test/dune
+++ b/test/dune
@@ -1,3 +1,4 @@
   (name decimal_test)
+  (deps (glob_files data/*))
   (libraries angstrom decimal))

It’ll then make sure that those files make it into the _build directory as and when they are required.

Unrelated aside: you probably want to raise your lower OCaml bound and/or use (preprocess future_syntax), since your tests rely on 4.08’s let-binding operators.

1 Like

Thank you! You’re totally right, I’ll raise the lower bound too.

1 Like