package b0

  1. Overview
  2. Docs
Software construction and deployment kit

Install

dune-project
 Dependency

Authors

Maintainers

Sources

b0-0.0.6.tbz
sha512=e9aa779e66c08fc763019f16d4706f465d16c05d6400b58fbd0313317ef33ddea51952e2b058db28e65f7ddb7012f328c8bf02d8f1da17bb543348541a2587f0

doc/b0.std/B0_testing/Test/T/index.html

Module Test.TSource

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

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

The type for testing values of type 'a.

Sourceval 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_tester.
  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.
Sourceval equal : 'a t -> 'a -> 'a -> bool

equal t is the equality function of t.

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

pp t is the formatting function of t.

Sourceval 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

Sourceval true' : 'a t

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

Sourceval false' : 'a t

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

Sourceval any : 'a t

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

Exceptions

Sourceval exn : exn t

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

Sourceval invalid_arg : exn t

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

Sourceval failure : exn t

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

Base types

Sourceval unit : unit t

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

Sourceval bool : bool t

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

Sourceval int : int t

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

Sourceval int32 : int32 t

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

Sourceval uint32 : int32 t

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

Sourceval int64 : int64 t

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

Sourceval uint64 : int64 t

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

Sourceval nativeint : nativeint t

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

Sourceval nativeuint : nativeint t

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

Sourceval 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.Lit.floatl.

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

Sourceval hex_float : float t

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

Characters and strings

Sourceval char : char t

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

Sourceval ascii_string : string t

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

Sourceval string : string t

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

Sourceval binary_string : string t

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

Sourceval styled_string : string t

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

Sourceval lines : string t

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

Sourceval bytes : bytes t

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

Parametric types

Sourceval 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.Lit.option.

Sourceval 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.Lit.either.

Sourceval result : ok:'a t -> ('a, string) 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.Lit.result.

Sourceval result' : ok:'a t -> error:'e t -> ('a, 'e) 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.Lit.result.

Sourceval 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.Lit.list.

Sourceval 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.Lit.array.

Sourceval 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.Lit.pair.

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

t2 is pair.

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

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

Sourceval 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.List.t4.

Sourceval 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.List.t5.

Sourceval 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.List.t6.