The ppx_hegel_test PPX emits a registration call for every let%hegel_test definition. When a library opts in to the dune (inline_tests (backend ppx_hegel_test)) stanza, dune synthesises an executable whose entry point calls test_main, which iterates the registry, runs each test, prints pass/fail status, and exits non-zero if any test failed. You can also register and run tests manually.
Metadata captured by the PPX for a single registered test.
Sourceval register : name:string ->file:string ->line:int ->(unit -> unit)-> unit
register ~name ~file ~line run adds a test to the global registry. The PPX emits one call per let%hegel_test at module-init time. Tests are ordered by registration.
You can register tests manually without the PPX. run is any unit -> unit that raises on failure, normally a wrapped Hegel.run_hegel_test:
let () =
Hegel_test_runtime.register ~name:"addition_commutes" ~file:__FILE__ ~line:__LINE__
(fun () ->
Hegel.run_hegel_test (fun tc ->
let a = Hegel.draw tc (Hegel.Generators.integers ()) in
let b = Hegel.draw tc (Hegel.Generators.integers ()) in
assert (a + b = b + a)))
test_main () runs every registered test via run_all and terminates the process with exit code 0 on success or 1 on any failure. This is the entry point that dune's inline-tests runner invokes: