B0_testing.TestAssertion tests and test infrastructure.
The type for text 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 while we wait for implicit source location support to be integrated in the compiler . The idea is that the argument is simply used with Stdlib.__POS__. For example:
Test.string s0 s1 ~__POS__module Log : sig ... endLogging.
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.
doc is a synopsis for the test executable.name is a name for the test executable. Defaults to the basename of Sys.executable_name.See an example.
set_main_exit f will disable the final report performed by main and invoke f instead. TODO. A bit ad-hoc.
module Arg : sig ... endTest arguments.
val test' : 'a Arg.t -> ?long:bool -> string -> ('a -> unit) -> 'a -> unittest' arg is like test but takes an argument. See the cookbook.
val autorun : ?args:Arg.value list -> unit -> unitautorun () calls all the tests defined by test and test', possibly filtered by the command line. args defines the value of test arguments.
A test is usually made of many assertions. If an assertion fails the test fails.
val fail : 'a Log.tval failstop :
?__POS__:loc ->
('a, Stdlib.Format.formatter, unit, 'b) Stdlib.format4 ->
'aval error_to_failstop : ?__POS__:loc -> ('a, string) Stdlib.result -> 'aerror_to_failstop (Error e) is failstop "%s" e.error_to_failstop (Ok v) is v.val error_to_fail : ?__POS__:loc -> ('a, string) Stdlib.result -> uniterror_to_fail (Error e) is fail "%s" e.error_to_fail (Ok v) is ().Blocks and loops can be used as larger sub units of test which you can skip, stop and failstop without skipping or stopping the test itself.
val block :
?kind:string ->
?pass:(?__POS__:loc -> int -> unit) ->
?fail:(?__POS__:loc -> int -> assertions:int -> unit) ->
?__POS__:loc ->
(unit -> unit) ->
unitblock ~kind ~pass ~fail f runs f (), if that results in:
n > 0 failed assertions, fail n ~assertions is called afterwards with assertions the total number of assertions that were performed. The default prints the fail to count ratio of assertions of type kind ("example", "test", etc.) if specified.f peforms a failstop the block is stopped but not the test. It is possible to fail stop the test by stoppping in the fail function.pass is called with the number of assertions. Defaults does nothing, unless kind if specified in which case it indicates that count kinds passed.For example if you are testing a list of examples use:
Test.block ~kind:"example" (fun () -> List.iter test_example examples)This will log either the number of examples that succeeded or the ratio of failures. See this example in the cookbook.
val range :
?kind:string ->
first:int ->
last:int ->
?__POS__:loc ->
(int -> unit) ->
unitrange ~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".
val dir : unit -> B0_std.Fpath.tdir () is the test directory. See the cookbook for more information.
module type T = sig ... endThe type for testable values.
module T : sig ... endTesters.
module Diff : sig ... endReporting value differences.
module Patch : sig ... endPatching text and files.
See the predefined assertions.
The type for functions asserting 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.
val holds : ?msg:string -> ?__POS__:loc -> bool -> unitholds b asserts that b is true. msg is logged if the assertion fails.
See the predefined snapshots.
module Snapshot : sig ... endSnapshot tests.
type 'a snap = ?__POS__:loc -> ?diff:'a Diff.t -> 'a -> 'a Snapshot.t -> unitThe type for snapshot functions.
val snap : ?subst:'a Snapshot.subst -> 'a T.t -> 'a snapsnap 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.
module Rand : sig ... endRandomized tests.
val noraise : ?__POS__:loc -> (unit -> 'a) -> 'anoraise 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.
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.
val nativeint : nativeint eqnativeint is eq T.nativeint.
val nativeuint : nativeint eqnativeuint is eq T.nativeuint.
val binary_string : string eqbinary_string is eq T.binary_string. Assumes arbitrary binary strings.
val styled_string : string eqstyled_string is eq T.styled_string. Assumes strings with ANSI escape sequences.
either ~left ~right is eq (T.either ~left ~right).
result' ~ok ~error is eq (T.result' ~ok ~error).
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.
These modules are not needed for basic B0_testing usage.
module Cli : sig ... endCommand line.
module Fmt : sig ... endFormatters for test runners and tested values.