B0_testing.SnapSnapshots tests.
These combinators can be used to snapshot values. They are based on the Test.snap primitive. Snapshots can be stored directly in the source code or in external files.
To be able to correct the snapshots when they change, access to these files must be provided. They are assumed to be in a file hierarchy rooted in the Test.dir directory which must be properly setup by the test runner. See the --test-dir option of test executable and b0's test directory support. Using B0_ocaml.test does the right thing.
While we wait for implicit source location support to be integrated in the compiler the combinators are expected to be used as follows:
Snap.string ("a" ^ "b") @> __POS_OF__ "ab";
Snap.string ("a" ^ "b") !@ (Fpath.v "snapshots/ab.string") ~__POS__module T = Test.TRepeated here for convenience, e.g. Snap.(list T.int).
val exn : exn Test.snapexn is Test.snap Test.T.exn.
val raise :
?ret:'a Test.T.t ->
?exn:exn Test.T.t ->
?diff:exn Test.Diff.t ->
?__POS__:Test.loc ->
(unit -> 'a) ->
exn Test.Snapshot.t ->
unitraise f snapshots the exception raised by f by printing it using exn (defaults to T.exn). The combinators fails if no exception is raised by f.
val unit : unit Test.snapunit is Test.snap Test.T.unit.
val bool : bool Test.snapbool is Test.snap Test.T.bool.
val int : int Test.snapint is Test.snap Test.T.int. Warning. Depending on their magnitude integer snapshots may not be portable across 64-bit and 32-bit platforms.
val int32 : int32 Test.snapint32 is Test.snap Test.T.int32
val uint32 : int32 Test.snapuint32 is Test.snap Test.T.uint32
val int64 : int64 Test.snapint64 is Test.snap Test.T.int64
val uint64 : int64 Test.snapuint64 is Test.snap Test.T.uint64
val nativeint : nativeint Test.snapnativeint is Test.snap Test.T.nativeint
val nativeuint : nativeint Test.snapnativeuint is Test.snap Test.T.nativeuint
val float : float Test.snapfloat is Test.snap Test.T.float. N.B. not exactly.
val hex_float : float Test.snaphex_float is Test.snap Test.T.hex_float N.B. not exactly.
Note. The string snapshoters have a special substitution function that respects quoted literals.
val char : char Test.snapchar is Test.snap Test.T.char.
val ascii_string : string Test.snapval string : string Test.snapval lines : string Test.snaplines uses Test.T.lines to produce the diffs.
result left right is Test.snap (Test.T.either left right)
result ok is Test.snap (Test.T.result ok)
result ok error is Test.snap (Test.T.result ok error)
list elt is Test.snap (Test.T.list elt)
array elt is Test.snap (Test.T.array elt)
pair fst snd is Test.snap (Test.T.pair fst snd)
t3 v0 v1 v2 is Test.snap for triplets.
t4 is Test.snap for quadruplets.
val t5 :
'a Test.T.t ->
'b Test.T.t ->
'c Test.T.t ->
'd Test.T.t ->
'e Test.T.t ->
('a * 'b * 'c * 'd * 'e) Test.snapt5 is Test.snap for quintuplets.
val t6 :
'a Test.T.t ->
'b Test.T.t ->
'c Test.T.t ->
'd Test.T.t ->
'e Test.T.t ->
'f Test.T.t ->
('a * 'b * 'c * 'd * 'e * 'f) Test.snapt6 is Test.snap for sextuplets.
val stdout :
?__POS__:Test.loc ->
?test:string T.t ->
?diff:string Test.Diff.t ->
?env:B0_std.Os.Env.assignments ->
?cwd:B0_std.Fpath.t ->
?stdin:B0_std.Os.Cmd.stdi ->
?stderr:[ `Stdo of B0_std.Os.Cmd.stdo | `Out ] ->
trim:bool ->
B0_std.Cmd.t ->
string Test.Snapshot.t ->
unitstdout cmd snapshots the standard output of the execution (see B0_std.Os.Cmd.run_status_out). The function Test.fails if there's any sort of error. The status is ignored.
val run :
?__POS__:Test.loc ->
?test:string T.t ->
?diff:string Test.Diff.t ->
?env:B0_std.Os.Env.assignments ->
?cwd:B0_std.Fpath.t ->
?stdin:B0_std.Os.Cmd.stdi ->
B0_std.Cmd.t ->
string Test.Snapshot.t ->
unitrun cmd snapshots the standard output, standard error and exit code of the execution (see B0_std.Os.Cmd.run).