Inline tests in private modules

I have created a new dune project with the following structure:

- bin
- lib
    - private
        * private.ml
        * foo.ml
    * my_lib.ml
    * dune

My dune file looks like this:

(include_subdirs qualified)
(library
 (name my_lib)
 (preprocess (pps ppx_inline_test ppx_expect))
 (inline_tests))

my foo.ml contains some inline tests:

let hello_generator name = "Hello " ^ name

let%expect_test "blah" = print_string @@ helo_generator "blah"; [%expect {|Hello blah|}]

and private.ml contains:

let hello = Foo.hello_generator

when I run dune runtest, I get the following error:

File "lib/dune", line 6, characters 1-15:
6 |  (inline_tests))
     ^^^^^^^^^^^^^^
Fatal error: exception Sys_error("$HOME/repos/my_project/_build/.sandbox/421aa677b2728e5983918ad9cb6d5a36/default/lib/foo.ml: No such file or directory")
Raised by primitive operation at Stdlib.open_in_gen in file "stdlib.ml", line 405, characters 28-54
Called from Stdlib.open_in_bin in file "stdlib.ml" (inlined), line 413, characters 2-47
Called from Ppx_expect_runtime__Write_corrected_file.f in file "runtime/write_corrected_file.ml", line 35, characters 21-48
Called from Base__List.map in file "src/list.ml", line 433, characters 15-18
...

I think this is probably related to the fact that Foo is not exposed, but I have no idea how to approach this.

What does my_lib.ml contain?

Though this sounds like a bug in dune

nothing interesting, honestly.

I also think this might be a bug.

The question is: is my_lib opening or using any module in private?
If not, maybe dune doesn’t detect private at all?

It does, and I think you’re right, but I find it really weird. I think I’ll just open a bug report with them.

2 Likes

in the end, it was a bug in ppx_expect and dune is alright here :slight_smile:

1 Like

I’m having a similar error. Do you know if this is fixed yet? At what version?