B0_testing.Test
Testing structure and combinators.
See an example.
Warning. Currently the testing combinators are not thread-safe. They will be made thread-safe when OCaml 5.0 is required.
The type for test source positions. This is the type of Stdlib.__POS__
.
It is an optional argument of most combinators to short-circuit the best effort failure location tracking performed via backtraces which may be unreliable in certain scenarios (e.g. closures). The idea is that the argument is simply used with Stdlib.__POS__
. For example:
Test.string ~__POS__ s0 s1;
Note that at the moment not all functions make use of the argument.
module Fmt : sig ... end
Formatters for test runners and tested values.
val main : ?__POS__:pos -> (unit -> unit) -> int
val test : ?__POS__:pos -> string -> (unit -> unit) -> unit
val stop : ?__POS__:pos -> unit -> 'a
A test
is usually made of many checks. If a check fails the test fails.
val pass : ?__POS__:pos -> unit -> unit
pass ()
increments the number of successfull checks.
val fail :
?__POS__:pos ->
('a, Stdlib.Format.formatter, unit, unit) Stdlib.format4 ->
'a
val failstop :
?__POS__:pos ->
('a, Stdlib.Format.formatter, unit, 'b) Stdlib.format4 ->
'a
val log :
?__POS__:pos ->
('a, Stdlib.Format.formatter, unit, unit) Stdlib.format4 ->
'a
log fmt …
logs a message formatted by fmt
.
val log_fail :
?__POS__:pos ->
('a, Stdlib.Format.formatter, unit, unit) Stdlib.format4 ->
'a
val range :
?kind:string ->
first:int ->
last:int ->
?__POS__:pos ->
(int -> unit) ->
unit
range ~first ~last f
calls f n
with n
ranging over the range [first
;last
]. If a failure occurs for n
, logs "%s in range [%d;%d] failed on %d" kind first last n
. If f
performs a failstop
the loop is stopped but not the test. kind
defaults to "Test"
.
val block :
?fail:(?__POS__:pos -> int -> checks:int -> unit) ->
?__POS__:pos ->
(unit -> unit) ->
unit
block ~fail f
runs f ()
, if that results in n > 0
failed checks, fail n ~checks
is called afterwards with checks
the total number of checks that were performed. If f
peforms a failstop
the block is stopped but not the test. It is possible to fail stop the test by stoppping in fail
.
val holds : ?msg:string -> ?__POS__:pos -> bool -> unit
holds b
asserts that b
is true
. msg
is logged if the assertion fails.
val raises : exn -> ?__POS__:pos -> (unit -> 'a) -> unit
raises exn f
tests that f ()
raises exception exn
.
val raises' : (exn -> bool) -> ?__POS__:pos -> (unit -> 'a) -> unit
raises is_exn f
tests that f ()
raises an exception exn
that satisfies is_exn exn
.
val invalid_arg : ?__POS__:pos -> (unit -> 'a) -> unit
invalid_arg f
tests that f ()
raises Invalid_argument _
.
val failure : ?__POS__:pos -> (unit -> 'a) -> unit
failure f
tests that f ()
raises Failure _
.
module Eq : sig ... end
Equality testers.
eq t v0 v1
assert v0
and v1
are equal are equal using equality tester t
.
neq t v0 v1
assert v0
and v1
are not equal using equality tester t
.
val bool : ?__POS__:pos -> bool -> bool -> unit
bool b0 b1
asserts that b0
and b1
are equal.
val char : ?__POS__:pos -> char -> char -> unit
char c0 c1
asserta that c0
and c1
are equal.
val int : ?__POS__:pos -> int -> int -> unit
int i0 i1
asserts that i0
and i1
are equal.
val int32 : ?__POS__:pos -> int32 -> int32 -> unit
int32 i0 i1
asserts that i0
and i1
are equal.
val uint32 : ?__POS__:pos -> int32 -> int32 -> unit
uint32 i0 i1
asserts that i0
and i1
are equal.
val int64 : ?__POS__:pos -> int64 -> int64 -> unit
int64 i0 i1
asserts that i0
and i1
are equal.
val uint64 : ?__POS__:pos -> int64 -> int64 -> unit
uint64 i0 i1
asserts that i0
and i1
are equal.
val nativeint : ?__POS__:pos -> nativeint -> nativeint -> unit
nativeint i0 i1
asserts that i0
and i1
are equal.
val float : ?__POS__:pos -> float -> float -> unit
float f0 f1
asserts that f0
and f1
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.
val string : ?__POS__:pos -> string -> string -> unit
string s0 s1
asserts that s0
and s1
are equal.
val binary_string : ?__POS__:pos -> string -> string -> unit
binary_string s0 s1
asserts that s0
and s1
are equal assuming that s0
and s1
is binary data.
val styled_string : ?__POS__:pos -> string -> string -> unit
styled_string s0 s1
asserts that s0
and s1
are equal assuming that s0
and s1
have ANSI escape sequences.
val bytes : ?__POS__:pos -> bytes -> bytes -> unit
string s0 s1
asserts that s0
and s1
are equal.
list ~elt l0 l1
assert lists l0
and l1
are equal using elt
to test elements (default to Eq.any
).
array ~elt a0 a1
assert arrays a0
and a1
are equal using elt
to test elements (defaults to Eq.any
).
val get_some : ?__POS__:pos -> 'a option -> 'a
option ~some:(module M) v0 v1
asserts options v0
and v1
are equal according to M
's equality (otherwise Stdlib.(=)
is used).
val get_ok : ?__POS__:pos -> ('a, string) Stdlib.result -> 'a
get_ok'
is like get_ok
but uses error
to render the error.
val result :
?ok:'a Eq.t ->
?__POS__:pos ->
('a, string) Stdlib.result ->
('a, string) Stdlib.result ->
unit
result ~ok r0 r1
asserts results r0
and r1
are equal according to ok
(defaults to Eq.any
).
val result' :
?ok:'a Eq.t ->
?error:'e Eq.t ->
?__POS__:pos ->
('a, 'e) Stdlib.result ->
('a, 'e) Stdlib.result ->
unit
result ~ok ~error r0 r1
asserts results r0
and r1
are equal according to ok
and error
(both default to El.eq
module Rand : sig ... end
Randomized testing.
module Cli : sig ... end
Command line