package b0

  1. Overview
  2. Docs
Software construction and deployment kit

Install

dune-project
 Dependency

Authors

Maintainers

Sources

b0-0.0.6.tbz
sha512=e9aa779e66c08fc763019f16d4706f465d16c05d6400b58fbd0313317ef33ddea51952e2b058db28e65f7ddb7012f328c8bf02d8f1da17bb543348541a2587f0

doc/b0.std/B0_testing/Snap/index.html

Module B0_testing.SnapSource

Snapshots.

These combinators can be used to snapshot values. They are based on the Test.snap primitive.

While we wait for implicit source location support to be integrated in the compiler they are expected to be used as follows:

Snap.bool (Bool.not true) @@ __POS_OF__ false;
Snap.string ("a" ^ "b") @@ __POS_OF__
  "ab";
Sourcemodule T = Test.T

Repeated here for convenience, e.g. Snap.(list T.int).

Exceptions

Sourceval exn : exn Test.snap

exn is Test.snap Test.T.snap.

Sourceval 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 -> unit

raise f snapshots the exception raised by f by printing it using exn (defaults to Exceptions). The combinators fails if no exception is raised by f.

Base types

Sourceval unit : unit Test.snap
Sourceval bool : bool Test.snap
Sourceval int : int Test.snap

int is Test.snap Test.T.int. Warning. Depending on their magnitude integer snapshots may not be portable across 64-bit and 32-bit platforms.

Sourceval int32 : int32 Test.snap
Sourceval uint32 : int32 Test.snap
Sourceval int64 : int64 Test.snap
Sourceval uint64 : int64 Test.snap
Sourceval nativeint : nativeint Test.snap
Sourceval nativeuint : nativeint Test.snap
Sourceval float : float Test.snap

float is Test.snap Test.T.float. N.B. not exactly.

Sourceval hex_float : float Test.snap

hex_float is Test.snap Test.T.hex_float N.B. not exactly.

Character and strings

Note. The string snapshoters have a special substitution function that respects quoted literals.

Sourceval char : char Test.snap
Sourceval ascii_string : string Test.snap
Sourceval string : string Test.snap
Sourceval line : string Test.snap

like string but on a single line.

Sourceval lines : string Test.snap

lines uses Test.T.lines to produce the diffs.

Parametric types

Sourceval option : 'a Test.T.t -> 'a option Test.snap

option t snapshots t option.

Sourceval either : 'a Test.T.t -> 'b Test.T.t -> ('a, 'b) Either.t Test.snap

result left right is Test.snap (Test.T.either left right)

Sourceval result : 'a Test.T.t -> ('a, string) result Test.snap

result ok is Test.snap (Test.T.result ok)

Sourceval result' : 'a Test.T.t -> 'e Test.T.t -> ('a, 'e) result Test.snap

result ok error is Test.snap (Test.T.result ok error)

Sourceval list : 'a Test.T.t -> 'a list Test.snap

list elt is Test.snap (Test.T.list elt)

Sourceval array : 'a Test.T.t -> 'a array Test.snap

array elt is Test.snap (Test.T.array elt)

Sourceval pair : 'a Test.T.t -> 'b Test.T.t -> ('a * 'b) Test.snap

pair fst snd is Test.snap (Test.T.pair fst snd)

Sourceval t2 : 'a Test.T.t -> 'b Test.T.t -> ('a * 'b) Test.snap

t2 is pair.

Sourceval t3 : 'a Test.T.t -> 'b Test.T.t -> 'c Test.T.t -> ('a * 'b * 'c) Test.snap

t3 v0 v1 v2 is Test.snap for triplets.

Sourceval t4 : 'a Test.T.t -> 'b Test.T.t -> 'c Test.T.t -> 'd Test.T.t -> ('a * 'b * 'c * 'd) Test.snap

t4 is Test.snap for quadruplets.

Sourceval 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.snap

t5 is Test.snap for quintuplets.

Sourceval 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.snap

t6 is Test.snap for sextuplets.

Command executions

Sourceval stdout : ?__POS__:Test.loc -> ?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 -> unit

stdout cmd snaphosts the standard output of the execution (see Os.run_status_out). The function Test.fails if there's any sort of error. The status is ignored (FIXME do something more sensitive we could assert it)).