Module Test.T

Testers.

A tester simply packs an equality function and a formatter to print values.

Important. We indicate when the printers respect the OCaml syntax. Only these testers are suitable for use with Test.snap.

Testers

type 'a t = (module T with type t = 'a)

The type for testing values of type 'a.

val make : ?equal:('a -> 'a -> bool) -> ?pp:'a B0_std.Fmt.t -> unit -> 'a t

make ~equal ~pp () is a tester using equal to assert values and pp to inspect them. Note the following points:

  1. If your module M implement T it can directly be used as an equality tester value as (module M), you don't need to call this function.
  2. If you want to use M with Test.snap note that it expects M.pp to output valid OCaml syntax. If that is not the case you can redefine it with with'.
  3. By convention the first argument of equal is the value to test and the second value is the reference value. This is somtimes used by the combinators.
val equal : 'a t -> 'a -> 'a -> bool

equal t is the equality function of t.

val pp : 'a t -> 'a B0_std.Fmt.t

pp t is the formatting function of t.

val with' : ?equal:('a -> 'a -> bool) -> ?pp:'a B0_std.Fmt.t -> 'a t -> 'a t

with' t is t with those arguments specified replaced.

Predefined testers

Generic

val true' : 'a t

true' equates all values and prints them with Test.Fmt.anon.

val false' : 'a t

false' distinguishes all values and prints them with Test.Fmt.anon.

val any : 'a t

any uses Stdlib.compare for testing equality (works Float.nan values) and prints them with Test.Fmt.anon.

Exceptions

val exn : exn t

exn uses Stdlib.compare for testing equality and prints with B0_std.Fmt.exn.

val invalid_arg : exn t

invalid_arg has an equality function that returns true iff the first argument is of the form Invalid_argument _.

val failure : exn t

failure has an equality function that returns true iff the first argument is of the form Failure _.

Base types

val unit : unit t

unit tests units and prints them as OCaml syntax with B0_std.Fmt.OCaml.unit.

val bool : bool t

bool tests booleans and prints them as OCaml syntax with B0_std.Fmt.OCaml.bool.

val int : int t

int tests integers and prints them as OCaml syntax with B0_std.Fmt.OCaml.int.

val int32 : int32 t

int32 tests 32-bit integers and prints them as OCaml syntax with B0_std.Fmt.OCaml.int32.

val uint32 : int32 t

uint32 tests unsigned 32-bit integers and prints them with B0_std.Fmt.OCaml.uint32

val int64 : int64 t

int64 tests 64-bit integers and prints them as OCaml syntax with B0_std.Fmt.OCaml.int64.

val uint64 : int64 t

uint64 tests unsigned 64-bit integers and prints them as OCaml syntax with B0_std.Fmt.OCaml.uint64.

val nativeint : nativeint t

nativeint tests native integers and prints them as OCaml syntax with B0_std.Fmt.OCaml.nativeint.

val nativeuint : nativeint t

nativeuint tests unsigned native integers and prints them as OCaml syntax with B0_std.Fmt.OCaml.nativeuint.

val float : float t

float tests float with Float.equal so it can be used to assert nan values and prints as OCaml syntax them with B0_std.Fmt.OCaml.float.

Warning. Be aware of the limitations of testing floats for strict binary equality.

val hex_float : float t

hex_float is like float but uses the OCaml syntax B0_std.Fmt.OCaml.hex_float for printing.

Characters and strings

val char : char t

char tests characters (bytes) and prints them as OCaml syntax with B0_std.Fmt.OCaml.char.

val ascii_string : string t

ascii_string tests strings and prints them as OCaml syntax with B0_std.Fmt.OCaml.ascii_string.

val string : string t

string tests strings and prints them as OCaml syntax with B0_std.Fmt.OCaml.string

val binary_string : string t

binary_string tests strings and prints them with as OCaml syntax with B0_std.Fmt.OCaml.binary_string.

val styled_string : string t

styled_string tests strings and prints them with with B0_std.Fmt.styled_text_string.

val lines : string t

lines tests strings and prints them by lines using B0_std.Fmt.lines.

val bytes : bytes t

bytes tests bytes and prints them with B0_std.Fmt.bytes.

val bigbytes : (int, Stdlib.Bigarray.int8_unsigned_elt, Stdlib.Bigarray.c_layout) Stdlib.Bigarray.Array1.t t

bigbytes tests bigbytes and prints them with B0_std.Fmt.bigbytes

Type constructors

val option : 'a t -> 'a option t

option v tests options of values tested with v and prints them as OCaml syntax with B0_std.Fmt.OCaml.option.

val either : left:'a t -> right:'b t -> ('a, 'b) Either.t t

either ~left ~right tests Either.t values and prints them as OCaml syntax with B0_std.Fmt.OCaml.either.

val result : ok:'a t -> ('a, string) Stdlib.result t

result ok tests result values using ok for Ok and a string for Error and prints them as OCaml syntax with B0_std.Fmt.OCaml.result.

val result' : ok:'a t -> error:'e t -> ('a, 'e) Stdlib.result t

result ok error tests result values using the given equalities for the values of each cas and prints them as OCaml syntax with B0_std.Fmt.OCaml.result.

val list : 'a t -> 'a list t

list elt tests list of elements tested with elt and prints them as OCaml syntax with B0_std.Fmt.OCaml.list.

val array : 'a t -> 'a array t

array elt test array of elements tested with elt and prints them as OCaml syntax with B0_std.Fmt.OCaml.array.

val pair : 'a t -> 'b t -> ('a * 'b) t

pair fst snd tests pairs with fst and snd and prints them as OCaml syntax with B0_std.Fmt.OCaml.pair.

val t2 : 'a t -> 'b t -> ('a * 'b) t

t2 is pair.

val t3 : 'a t -> 'b t -> 'c t -> ('a * 'b * 'c) t

t3 tests triplets and prints them as OCaml syntax with B0_std.Fmt.OCaml.t3.

val t4 : 'a t -> 'b t -> 'c t -> 'd t -> ('a * 'b * 'c * 'd) t

t4 tests quadruplets and prints them as OCaml syntax with B0_std.Fmt.OCaml.t4.

val t5 : 'a t -> 'b t -> 'c t -> 'd t -> 'e t -> ('a * 'b * 'c * 'd * 'e) t

t5 tests quintuplets and prints them as OCaml syntax with B0_std.Fmt.OCaml.t5.

val t6 : 'a t -> 'b t -> 'c t -> 'd t -> 'e t -> 'f t -> ('a * 'b * 'c * 'd * 'e * 'f) t

t6 tests sextuplets and prints them as OCaml syntax with B0_std.Fmt.OCaml.t6.