[dune] How to specify dependency to an executable?

I’m developing an executable and want to cram-test it. But I don’t know a way to add a strict dependency from tests to my executable. MVP. The call dune build @install && dune test helps but I want a dependency…

➜  dune-exec-cram-demo git:(master) ✗ cat test.t/run.t                                                                                         4.12.1+flambda
  $ dune build
$ echo $PATH
  $ which asdf
  [1]
  $ asdf
  asdf: not found
  [127]
  $ qwe
  qwe: not found
  [127]
➜  dune-exec-cram-demo git:(master) ✗ cat test.t/dune                                                                                          4.12.1+flambda
(cram
 (deps
  %{workspace_root}/src/asdf
  %{workspace_root}/src/asdf.exe
  %{bin:asdf}
  %{bin:qwe}
  %{workspace_root}/qwe.exe))

(library
 (name lib1)
 (modules lib1))

In dune-release we use the following to depend on our binary that is installed (has a public_name) and one that is not installed (just a helper for cleaning test output):


(env
 (_
  (binaries
   (../helpers/make_dune_release_deterministic.exe as
     make_dune_release_deterministic))))

(cram
 (deps %{bin:dune-release} %{bin:make_dune_release_deterministic}))

So weirdly I don’t get the same result as you, and for me it works…
I don’t think the dune files inside the test.t should do anything according to Writing and Running Tests — dune documentation
It also works for me without test.t/dune and test.t/dune-project, but with

> cat test.t/run.t
  $ which asdf
  $ asdf
  $ qwe
> git diff dune
diff --git a/dune b/dune
index 1d907b5..a680c9b 100644
--- a/dune
+++ b/dune
@@ -2,3 +2,11 @@
  (public_name qwe)
  (package package1)
  (name qwe))
+
+
+(cram
+ (deps
+   %{bin:asdf}
+   %{bin:qwe}
+ )
+)
> dune clean && dune runtest
diff --git a/../../../default/test.t/run.t b/test.t/run.t.corrected
index f9f6a51..9bab56a 100644
--- a/../../../default/test.t/run.t
+++ b/test.t/run.t.corrected
@@ -1,3 +1,6 @@
   $ which asdf
+  path/to/dune-test-exec-dependencies/_build/install/default/bin/asdf
   $ asdf
+  Hello, World!
   $ qwe
+  Hello, World!

Does this work for you ?

Thanks @bnguyenvanyen

I needed to specify that executables are used in cram tests in dune file where I define executables, not in dune files for tests. Wondering why dune didn’t show any warning about that…