Redirect stdin from a file in a dune custom test

I’m trying to write a custom test where I feed some test data to the main executable of my project via standard in. Is there a way to do this?

Here’s what I have so far.

(alias
 (name runtest)
 (deps test_data.txt)
 (action (run dune exec my_proj_exe < test.txt))
)

I don’t think the redirect actually works, since the test hangs. I think < is treated as an argument to dune.

This is not possible via the action DSL at the moment, you need to use a shell command: (system "my_proj_exe < test.txt"). Although, it seems like a (with-stdin-from <file> <action>) construction would be a fine addition since we already have (with-stdout-to <file> <action>).

BTW, calling dune exec here feels a bit odd, why not do (run my_proj_exe ...) directly?

1 Like

I had dune exec because I didn’t know that I could just call the program directly. Thanks for letting me know!

For info, (with-stdin-from ...) has just been merged into dune: https://github.com/ocaml/dune/pull/2487

3 Likes