package tezt

  1. Overview
  2. Docs

Base functions.

Strings

val (//) : string -> string -> string

Same as Filename.concat.

val sf : ('a, unit, string) Stdlib.format -> 'a

Same as Printf.sprintf.

Concurrency Monad

val let* : 'a Lwt.t -> ('a -> 'b Lwt.t) -> 'b Lwt.t

Same as Lwt.bind.

val and* : 'a Lwt.t -> 'b Lwt.t -> ('a * 'b) Lwt.t

Same as Lwt.both.

val and*! : 'a Lwt.t -> 'b Lwt.t -> ('a * 'b) Lwt.t

Same as Lwt.both, but immediately propagate exceptions.

More precisely, if one of the two promises is rejected or canceled, cancel the other promise and reject the resulting promise immediately with the original exception.

val return : 'a -> 'a Lwt.t

Same as Lwt.return.

val unit : unit Lwt.t

Same as Lwt.return_unit.

val none : 'a option Lwt.t

Same as Lwt.return_none.

val some : 'a -> 'a option Lwt.t

Same as Lwt.return_some.

Lists

val range : int -> int -> int list

Make a list of all integers between two integers.

If the first argument is greater than the second argument, return the empty list.

val list_find_map : ('a -> 'b option) -> 'a list -> 'b option

Backport of List.find_map from OCaml 4.10.

val take : int -> 'a list -> 'a list

take n l returns the first n elements of l if longer than n, else l itself.

Regular Expressions

type rex

Compiled regular expressions.

val rex : string -> rex

Compile a regular expression using Perl syntax.

val show_rex : rex -> string

Convert a regular expression to a string using Perl syntax.

val (=~) : string -> rex -> bool

Test whether a string matches a regular expression.

Example: "number 1234 matches" =~ rex "\\d+"

val (=~!) : string -> rex -> bool

Negation of =~.

val (=~*) : string -> rex -> string option

Match a regular expression with one capture group.

val (=~**) : string -> rex -> (string * string) option

Match a regular expression with two capture groups.

val replace_string : ?pos:int -> ?len:int -> ?all:bool -> rex -> by:string -> string -> string

replace_string ~all rex ~by s iterates on s, and replaces every occurrence of rex with by. If all = false, then only the first occurrence of rex is replaced.

Promises

val repeat : int -> (unit -> unit Lwt.t) -> unit Lwt.t

Repeat something a given amount of times.

Input/Output

val with_open_out : string -> (Stdlib.out_channel -> unit) -> unit

Open file, use function to write output then close the output. In case of error while writing, the channel is closed before raising the exception

val with_open_in : string -> (Stdlib.in_channel -> 'a) -> 'a

Open file, use function to read input then close the input. In case of error while reading, the channel is closed before raising the exception *

val read_file : string -> string Lwt.t

read_file filename returns the full contents of file filename

Common structures

module String_map : Stdlib.Map.S with type key = string
module String_set : Stdlib.Set.S with type elt = string