B0_testing.Test
Testing structure and combinators.
test name f
runs the test in f
. The test fails if it raises an unexpected exception. name
is logged before f
is executed. This is typically called this way:
let mytest () =
Test.test "Something" @@ fun () ->
assert (1 = 1); …
()
main f
executes f ()
and reports the testing status. The returned integer is the number of failing tests which should be given to exit
.
f
typically calls function that call test
. Your typical main should look like this::
let main () =
Test.main () @@ fun () ->
my_test ()
…
let () = if !Sys.interactive then exit (main ())
This structure ensures you can load and run its components in the toplevel, e.g. via b0 -- .ocaml.ocaml
val repeat :
fail:(int -> 'b, Stdlib.Format.formatter, unit, unit) Stdlib.format4 ->
int ->
(int -> 'a) ->
unit
repeat ~fail n f
calls f
with n
to 1
stopping if it fails and logging log fail n
.
raises is_exn f
tests that f ()
raises an exception exn
that satisfies is_exn exn
.
log fmt …
logs a message formatted by fmt
log_fail fmt …
is like log
but for failures.