A t typ equips a type t with a pretty printer, and either an equality or a comparison function.
All types can be used with eq and neq, but some types will result in an exception when used with lt, le, gt and ge. Such types are said to be non comparable.
For all functions of this section, if the test fails, the function calls Test.fail with the error message given in ~error_msg. This ~error_msg may contain placeholders %L and %R where:
%L is replaced by the left-hand side value of the operator;
%R is replaced by the right-hand side value of the operator.
Here are some examples of ~error_msg for inspiration:
"expected filename = %R, got %L"
"expected list size >= %R, got %L"
"expected f to be monotonous, got f x = %L and f y = %R with x < y"
Comparison Operators
Sourceval (=) : 'a->'a->?__LOC__:string ->'atyp->error_msg:string -> unit
Check that a value is equal to another.
Example: Check.((value = expected) int ~error_msg:"expected value = %R, got %L")
Sourceval (<>) : 'a->'a->?__LOC__:string ->'atyp->error_msg:string -> unit
Check that a value is not equal to another.
Example: Check.((value <> wrong) int ~error_msg:"expected value <> %R")
Sourceval (<) : 'a->'a->?__LOC__:string ->'atyp->error_msg:string -> unit
Check that a value is less than another.
Example: Check.((value < threshold) int ~error_msg:"expected value < %R, got %L")
Sourceval (<=) : 'a->'a->?__LOC__:string ->'atyp->error_msg:string -> unit
Check that a value is less than or equal to another.
Example: Check.((value <= threshold) int ~error_msg:"expected value <= %R, got %L")
Sourceval (>) : 'a->'a->?__LOC__:string ->'atyp->error_msg:string -> unit
Check that a value is greater than another.
Example: Check.((value > threshold) int ~error_msg:"expected value > %R, got %L")
Sourceval (>=) : 'a->'a->?__LOC__:string ->'atyp->error_msg:string -> unit
Check that a value is greater than or equal to another.
Example: Check.((value >= threshold) int ~error_msg:"expected value >= %R, got %L")
Sourceval (=~) : string ->Base.rex->error_msg:string -> unit
Check that a string matches a regular expression.
Example: Check.((value =~ rex) ~error_msg:"expected value =~ %R, got %L")
Sourceval (=~!) : string ->Base.rex->error_msg:string -> unit
Check that a string does not match a regular expression.
Example: Check.((value =~! rex) ~error_msg:"expected value =~! %R, got %L")
Predicates on Lists
Sourceval list_mem :
'atyp->?__LOC__:string ->'a->'a list->error_msg:string ->
unit
Check that a value belongs to a list.
Example: Check.list_mem int i list int ~error_msg:"expected %L to be in the list") *
Sourceval list_not_mem :
'atyp->?__LOC__:string ->'a->'a list->error_msg:string ->
unit
Check that a value does not belong to a list.
Example: Check.list_not_mem int i list int ~error_msg:"expected %L to not be in the list") *
Predicates on Exceptions
Sourceval raises :
?__LOC__:string ->exn ->(unit -> unit)->error_msg:string ->
unit
Check that evaluating the given function raises the expected exception.
Example: Check.raises f exn ~error_msg:"expected f to raise %L, got %R"
Predicates on files
Sourceval file_exists : ?__LOC__:string ->string -> unit
Check that a file with the given name exists.
Sourceval file_not_exists : ?__LOC__:string ->string -> unit
Check that a file with the given name does not exist.
Sourceval directory_exists : ?__LOC__:string ->string -> unit
Check that a directory with the given name exists.
This directory_exists path succeeds if there is a file at path and it is a directory.
Sourceval directory_not_exists : ?__LOC__:string ->string -> unit
Check that a directory with the given name does not exist.
This directory_not_exists path succeeds either if there is a non-directory file at path or if there is no file at path.
Predicates on booleans
Sourceval is_true : ?__LOC__:string ->bool ->error_msg:string -> unit
Check that a boolean is true.
Example: Check.is_true cond ~error_msg:"expected condition to be true"
Sourceval is_false : ?__LOC__:string ->bool ->error_msg:string -> unit
Check that a boolean is false.
Example: Check.is_false cond ~error_msg:"expected condition to be false"