Building a test runner with ppx_inline_test

ppx
testing
jbuilder

#1

I am trying to use ppx_inline_test with jbuilder. I am starting out by writing a basic failing test:

file test.ml:

let%test _ = false

let () : unit =
  Ppx_inline_test_lib.Runtime.exit ()

file jbuild:

(jbuild_version 1)

(executable
 ((name test)
  (libraries (ppx_inline_test.runner.lib))
  (preprocess (pps (ppx_jane ppx_driver.runner)))))

run:

jbuilder build test.exe

When I run this command, I get

Error: ppx_inline_test: extension is disabled because the tests would be ignored (the build system didn't pass -inline-test-lib)

How do I pass -inline-test-lib in jbuilder?


#2

I figured it out.

file jbuild:

(jbuild_version 1)

(executable
 ((name test)
  (libraries (ppx_inline_test.runner.lib))
  (preprocess (pps (ppx_jane ppx_driver.runner (-inline-test-lib test))))))

After building, execute:

./_build/default/test.exe inline-test-runner test

#3

For convenience, you may want to include something like the following in your jbuild file:

(alias
 ((name runtest)
  (deps (test.exe))
  (action (run ${<} inline-test-runner test))
))

Then you can run your tests simply with jbuilder runtest. Also, the --no-buffer flag may be useful.


#4

I tried doing this and ran into:

Multiple rules generated for _build/default/src/test.o

Is there a way to handle this without manually listing every module in the library? :\


#5

If you have a library rule that’s also implicitly using the Test module, you can exclude it using the Ordered Set Language:

(library
  ((name some_lib)
   (modules (:standard \ test))))