package b0
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha512=e9aa779e66c08fc763019f16d4706f465d16c05d6400b58fbd0313317ef33ddea51952e2b058db28e65f7ddb7012f328c8bf02d8f1da17bb543348541a2587f0
doc/b0.std/B0_testing/Test/index.html
Module B0_testing.TestSource
Testing structure and assertions.
See an example.
Source locations
The type for test source locations. This is the type of Stdlib.__POS_OF__.
It is an optional argument of most combinators to keep track of precise locations of failures. The idea is that the argument is simply used with Stdlib.__POS__. For example:
Test.string s0 s1 ~__POS__Logging
The type for log functions. If __POS__ is specified starts by logging the position on a line before logging the format.
log_finish ends a line started with log_start.
log_raw fmt … outputs to the test log.
Main & tests
main f executes f (), logs the resulting testing status and returns 0 if all tests passed and 1 otherwise to be given to Stdlib.exit. Usually f calls functions that call test.
docis a synopsis for the test executable.nameis a name for the test executable.
See an example.
val main' :
?man:Cmdliner.Manpage.block list ->
?doc:string ->
?name:string ->
'a Cmdliner.Term.t ->
('a -> unit) ->
intmain' is like main but allows to define your own additional command line.
set_main_exit f will disable the final report performed by main and invoke f instead. TODO. A bit ad-hoc.
test' arg is like test but takes an argument.
Stop, pass, skip and fail
A test is usually made of many assertions. If an assertion fails the test fails.
pass () increments the number of successfull assertions.
Blocks and loops
Blocks and loops can be used as larger sub units of test which you can stop and failstop without stopping the test itself.
val block :
?fail:(?__POS__:loc -> int -> assertions:int -> unit) ->
?__POS__:loc ->
(unit -> unit) ->
unitblock ~fail f runs f (), if that results in n > 0 failed assertions, fail n ~assertions is called afterwards with assertoins the total number of assertions 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.
TODO. Should we simply make blocks nested tests ?
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".
Testers
Assertions
The type for functions aasserting equality. diff indicates how to report differences on mismatches.
eq t fnd exp assert fnd and exp are equal using tester t.
Convention. When testing values we assume that the second value is the expected argument and the first one the value against which it is checked.
holds b asserts that b is true. msg is logged if the assertion fails.
Exceptions
noraise f tests that f () does not raise an exception and fail stops if it does except if this is a B0_std.Os.exn_don't_catch exception.
catch f k calls f () and gives the exception it raises to k or fails otherwise. ret is used to print an offending returned value. B0_std.Os.exn_don't_catch exceptions are not catched.
ex is eq Exceptions.
val raises :
?ret:'a T.t ->
?exn:exn T.t ->
?diff:exn Diff.t ->
?__POS__:loc ->
exn ->
(unit -> 'a) ->
unitraises exn f tests that f () raises exception exn. B0_std.Os.exn_don't_catch exceptions are not catched.
invalid_arg f tests that f () raises Invalid_argument _. Note. It is usually better to use Snap.raise as it allows to keep track of the error message.
failure f tests that f () raises Failure _. Note. It is usually better to use Snap.raise as it allows to keep track of the error message.
Base types
nativeint is eq T.nativeint.
nativeuint is eq T.nativeuint.
Character and strings
binary_string is eq T.binary_string. Assumes arbitrary binary strings.
styled_string is eq T.styled_string. Assumes strings with ANSI escape sequences.
Parametric types
either ~left ~right is eq (T.either ~left ~right).
result' ~ok ~error is eq (T.result' ~ok ~error).
t4 is eq for quadruplets.
t5 is eq for quintuplets.
val t6 :
'a T.t ->
'b T.t ->
'c T.t ->
'd T.t ->
'e T.t ->
'f T.t ->
('a * 'b * 'c * 'd * 'e * 'f) eqt6 is eq for sextuplets.
Randomized testing
Snapshot testing
The type for snapshot functions.
snap t fnd @@ __POS_OF__ exp compares snapshot fnd to exp. subst is used to correct snapshots, it defaults to Snapshot.generic_subst which depends on t's pretty printer formatting valid OCaml code.
See B0_testing.Snap for preapplied combinators.
Low-level modules
These modules are not needed for basic B0_testing usage.