Quantcast
Channel: OCaml - Topics tagged dune
Viewing all articles
Browse latest Browse all 520

Using files in tests with Dune

$
0
0

Hi folks,

Often, when I write tests, I want to use separate files for, say, expected output rather than putting that in the .ml file of the tests.

If I just create a file under test (i.e next to the test module itself) and try to read that in the test:

open OUnit2

let tests =
  "it does something" >::
    (fun _ ->
      let  _ = 
      open_in "some_file"
      |> input_line in

      ()
    )

let _ = run_test_tt_main tests

then the test will fail with a Sys_error("some_file: No such file or directory") because it’s being run from the _build/default/test directory and the file hasn’t been copied there.

How do I copy the file to the build directory with Dune so that it can be found when running the test?

I tried using a copy action in my dune file in the test directory:

(test
 (name my_project)
 (libraries ounit2)
 (action (copy %{project_root}/test/some_file .)))

but that fails with

Error: Aliases must not have targets, however I inferred that these files
will be created by this action:
- test

What is the correct way to do this?

Thank you.

3 posts - 3 participants

Read full topic


Viewing all articles
Browse latest Browse all 520

Trending Articles