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); Test.int 1 1; …
()
main f
executes f ()
and reports the testing status, 0
if everything went right, 1
if a test failed.
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
.
is_error' ~msg r
tests that r
is Error msg
or Error _
if msg
is unspecified.
int i0 i1
asserts that i0
and i1
are equal. This uses Float.equal
so it can be used to assert NaN
values, also you should be aware of the limitations that are involved in testing floats for equality.
module type EQ = sig ... end
Types with equality and formatters.
eq (module M) v0 v1
assert v0
and v1
are equal.
neq (module M) v0 v1
assert v0
and v1
are not equal.
log fmt …
logs a message formatted by fmt
.
log_fail fmt …
is like log
but for failures.