How to use helper scripts in cram tests with dune

In my project, I have a lot of different cram test directories and they each use some of the same scripts to sanitize output, check for files, stuff like that. Right now, I just duplicate each of the helper scripts into the cram test directories so they are available to the test. Something like this:

- test
  - bar.t
    - run.t
	- sanitize.pl
  - foo.t
    - run.t
	- sanitize.pl # this is the same file as above

I would like to be able to organize them like this, so that the sanitize.pl script isn’t duplicated.

- test
  - bar.t
    - run.t
  - foo.t
    - run.t
  - scripts
    - sanitize.pl

I tried to refer to the script in my cram tests using the PWD or $(pwd) and then using a relative path from that. While that does point to the correct file, in terms of the actual test, none of the files outside of the current test dir (eg, bar.t) are actually present in the sandboxed test (eg, I don’t have access to any files outside of bar.t during the test).

tl;dr

Is there any way to have shared “helper scripts” in cram tests when using dune?

I haven’t tried it myself, but the documentation has an example showing how to declare dependencies for a set of cram tests, using (cram (deps ...)), see Writing and running tests — dune documentation for the details.

Cheers,
Nicolas

Ah yeah I had been using that stanza for the ocaml executable under test, but didn’t realize it could also be used for non-ocaml dependencies. I just tried it and it works fine, thanks!

Now I feel silly for not trying that :laughing: