How can you build the test executable in dune without running the executable

dune

#1

I know dune run runs builds the inline test runner executable for tests and runs them. However, I just want to run the tests. How can I just get the executable for the test? Also, I tried running dune build to build the tests, but it does not produce the executable.


#2

As far as I know, dune does incremental builds, so if the test executable is already built, it will not rebuild it. But maybe somebody should confirm this!


#3

Yeah, there’s no need to optimize for this manually. Dune should do the minimum amount of work to run your tests if you’ve specified your dependencies precisely.

But in case, you still need to do this, you can do:

$ dune exec --no-build ./path/to/test.exe

#4

I think he was looking for:

dune build ./src/test.exe

#5

While we’re on the subject, is there a way of doing the same thing for inline tests?


#6

You can but the name of the executable is a bit more complicated, we generate it in a .<something> sub-directory. If you run dune with --verbose, or look in the _build/log, you can see the exact command that is being run.


#7

Thanks guys. I was able to build the test runner executable without running the test. As a result, I was able to make a script in OCaml that runs an individual test in a file without running an entire test for a library. I made this script because I was not able to find a command in dune that does this.

Come check out the script here: