package tezt
Install
Dune Dependency
Authors
Maintainers
Sources
md5=88c2d9d3da75ff554599bc34cbf5acbe
sha512=e60294514ecc4a989ce663ebb306e56f654dcfaffb7dbe5e3f05f5a13c9c2ff64dadde4a77b0d9a8567a76a6a7a2b25e0940ccd2a956ffcb85ff9300bfebe3bc
doc/tezt.core/Tezt_core/Check/index.html
Module Tezt_core.Check
Source
Assertions.
This module defines predicates that call Test.fail
when they do not hold. Using these predicates gives you more consistent error messages.
Comparable Types
Type descriptions.
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.
The unit type.
Not very useful on its own, but may be useful inside more structured types.
This type is comparable.
The boolean type.
Not very useful on its own since one can write if not b then Test.fail ...
, but may be useful inside more structured types.
This type is comparable with true > false
.
The character type.
This type is comparable. Characters are compared by comparing their byte representation.
The float type.
Note that testing float equality or inequality is often a bad idea. Prefer float_epsilon
when it makes sense.
This type is comparable.
The float type with an approximative equality function.
The argument is how much of a difference can two values have and still be considered equal.
This type is comparable.
The string type.
This type is comparable in lexicographic order, where each character is compared using the same comparison function as char
.
Make an option type.
If the item type is comparable, the result is comparable. None
is always lesser than Some _
.
Make a result type.
This type is comparable if both 'a typ
and 'e typ
are comparable.
Make a list type.
If the item type is comparable, the result is comparable in lexicographic order.
Make an array type.
If the item type is comparable, the result is comparable in lexicographic order.
Make a 2-tuple type.
If both item types are comparable, the result is comparable in lexicographic order.
Make a 3-tuple type.
If all item types are comparable, the result is comparable in lexicographic order.
Make a 4-tuple type.
If all item types are comparable, the result is comparable in lexicographic order.
Make a 5-tuple type.
If all item types are comparable, the result is comparable in lexicographic order.
val tuple8 :
'a1 typ ->
'a2 typ ->
'a3 typ ->
'a4 typ ->
'a5 typ ->
'a6 typ ->
'a7 typ ->
'a8 typ ->
('a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 * 'a7 * 'a8) typ
Make a 8-tuple type.
If all item types are comparable, the result is comparable in lexicographic order.
Make a type by encoding to another.
Usage: convert encode typ
Example: convert (fun { x; y } -> x, y) (tuple2 int string)
Values are converted to typ
using encode
before being pretty-printed or compared. The result type is comparable if typ
is comparable.
Return the pretty-printer associated to the given type.
Return the equality function associated to the given type.
Return the comparison function associated to the given type if it is comparable, else return None
.
Make a custom type from a pretty-printer and an equality function.
The result is not comparable.
Make a custom type from a pretty-printer and a comparison function.
Same as equalable
but takes a module.
Example: equalable_module (module String)
.
Same as comparable
but takes a module.
Example: comparable_module (module String)
.
Predicates
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
Check that a value is equal to another.
Example: Check.((value = expected) int ~error_msg:"expected value = %R, got %L")
Check that a value is not equal to another.
Example: Check.((value <> wrong) int ~error_msg:"expected value <> %R")
Check that a value is less than another.
Example: Check.((value < threshold) int ~error_msg:"expected value < %R, got %L")
Check that a value is less than or equal to another.
Example: Check.((value <= threshold) int ~error_msg:"expected value <= %R, got %L")
Check that a value is greater than another.
Example: Check.((value > threshold) int ~error_msg:"expected value > %R, got %L")
Check that a value is greater than or equal to another.
Example: Check.((value >= threshold) int ~error_msg:"expected value >= %R, got %L")
Check that a string matches a regular expression.
Example: Check.((value =~ rex) ~error_msg:"expected value =~ %R, got %L")
Check that a string does not match a regular expression.
Example: Check.((value =~! rex) ~error_msg:"expected value =~! %R, got %L")
Predicates on Lists
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")
*
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
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
Check that a file with the given name exists.
Check that a file with the given name does not exist.
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.
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
Check that a boolean is true.
Example: Check.is_true cond ~error_msg:"expected condition to be true"
Check that a boolean is false.
Example: Check.is_false cond ~error_msg:"expected condition to be false"