Dune rules, library targets and inline test runners

Is there a simpler way than doing the following to get the path of an inline test runner to a given source file (a test in a source file):

  • I know the path to be something like _build/default/test/foo/.LIBRARY.inline-tests/inline_test_runner_LIBRARY.exe
  • to get the name of the library LIBRARY I parse the output of dune rules -r test
  • I search for a sexp containing the source file and "library-name=\"LIBRARY\" which yields the name.
    The problem is that dune build test does not build the inline test runners, only dune test builds them, so there is no mention of the inline test runner in the output of dune rules -r test.

For example a file test/foo/bar.ml that is part of a library baz with the inline runner executable _build/default/test/foo/.baz.inline-tests/inline_test_runner_baz.exe: baz is the minimal amount of information I need, the path of the test runner’s executable would be the optimum.

I’ve tried parsing the dune file for the library containing the source file, but that only works for ‘simple’ ones and not for files like this:

(library
 (name dune_file_watcher_tests_lib)
 (modules dune_file_watcher_tests_lib)
 (libraries dune_file_watcher base stdune threads.posix stdio spawn))

(library
 (name dune_file_watcher_tests_macos)
 (modules dune_file_watcher_tests_macos)
 (inline_tests
  (enabled_if
   (and
    (<> %{env:CI=false} true) ;; in github action, CI=true
    (= %{system} macosx)))
  (deps
   (sandbox always)))
 (libraries
  dune_file_watcher
  dune_file_watcher_tests_lib
  ppx_expect.config
  ppx_expect.config_types
  ppx_expect.common
  base
  stdune
  ppx_inline_test.config
  threads.posix
  stdio
  spawn)
 (preprocess
  (pps ppx_expect)))

(library
 (name dune_file_watcher_tests_linux)
 (modules dune_file_watcher_tests_linux)
 (inline_tests
  (enabled_if
   (= %{system} linux))
  (deps
   (sandbox always)))
 (libraries
  dune_file_watcher
  dune_file_watcher_tests_lib
  ppx_expect.config
  ppx_expect.config_types
  ppx_expect.common
  base
  stdune
  ppx_inline_test.config
  threads.posix
  stdio
  spawn)
 (preprocess
  (pps ppx_expect)))

And ‘ask ChatGPT’ is not an option!

1 Like