package hegel

  1. Overview
  2. Docs
Hegel property-based testing library for OCaml

Install

dune-project
 Dependency

Authors

Maintainers

Sources

hegel-0.12.2-opam.tar.gz
md5=7e3e9fe22fa27bcbcc702709033ad9a0
sha512=457e53d4c45ef8470645eba6a3c93cf5938ca3f8b1e45fc40121a14d6bb1f7967a8242294ee6d7ddf76f7ff9a2f67b7be6a00eab8970360d65dac789cc039aad

doc/hegel.test_runtime/Hegel_test_runtime/index.html

Module Hegel_test_runtimeSource

Runtime registry and runner.

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.

Sourcetype test = {
  1. name : string;
  2. file : string;
  3. line : int;
  4. run : unit -> unit;
}

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)))
Sourceval registered : unit -> test list

registered () returns the list of currently registered tests in registration order.

  List.iter
    (fun (t : Hegel_test_runtime.test) ->
       Printf.printf "%s (%s:%d)\n" t.name t.file t.line)
    (Hegel_test_runtime.registered ())
Sourceval run_all : unit -> int

run_all () runs every registered test, prints a per-test status line, and returns the number of failures.

  match Hegel_test_runtime.run_all () with
  | 0 -> print_endline "all tests passed"
  | n -> Printf.eprintf "%d test(s) failed\n" n
Sourceval test_main : unit -> '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:

  let () = Hegel_test_runtime.test_main ()