Fluffy the Togekiss
Fluffy the Togekiss

Reputation: 363

Include Non-OCaml/Reason Files in Dune Build?

I'm new to OCaml and Dune, and I'm trying to set up a basic project with test cases. I want my test module to be able to read in text files from a subdirectory and process the input of those files. However, although I'm reading the Dune documentation, I'm having trouble finding the right stanzas to tell Dune to include a directory with no .ml files in it.

When I build my Dune project, it doesn't include the directory where I put my test files.

|-project
  |-lib
  |-test
    |-test_files (* Not included in _build *)
      test_input1.txt
      test_input2.txt
    tests.ml

It seems like a lot of stanzas, like include_subdirs, tell Dune to look for modules, but it appears that Dune will ignore non-module files. Is that what's going on? How do I work around this?

Upvotes: 2

Views: 123

Answers (1)

Fluffy the Togekiss
Fluffy the Togekiss

Reputation: 363

After continuing to scour the documentation, I've gotten this to work. Dune is ultimately trying to build packages, and to designate a non-executable file as belonging to a package, we can use the install stanza.

One things that I didn't realize before poking at the test output was that the order of the stanzas matters. Originally, I had the test stanza before the install stanza, which would fail. I only realized that this might make a difference after noticing that the error output included line numbers.

My final dune file looked like this:

(install
 (files
  (glob_files test_files/*.txt))
 (section share))

(test
 (name test_reader)
 (libraries typecheck alcotest))

Then, within my OCaml file, I could find the file at test_files/filename.txt.

Upvotes: -1

Related Questions