package tezt

  1. Overview
  2. Docs

Module Tezt_core.BaseSource

Base functions.

Strings

Sourceval (//) : string -> string -> string

Same as Filename.concat.

Sourceval sf : ('a, unit, string) format -> 'a

Same as Printf.sprintf.

Concurrency Monad

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

Same as Lwt.bind.

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

Same as Lwt.both.

Sourceval lwt_both_fail_early : '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.

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

Same as Lwt.return.

Sourceval unit : unit Lwt.t

Same as Lwt.return_unit.

Sourceval none : 'a option Lwt.t

Same as Lwt.return_none.

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

Same as Lwt.return_some.

Sourceval mandatory : string -> 'a option -> 'a

Get the value of an option that must not be None.

Usage: mandatory name option

name is used in the error message if option is None.

Lists

Sourceval range : int -> int -> int list

Make a list of all integers between two integers.

If the first argument a is greater than the second argument b, return the empty list. Otherwise, returns the list a; ...; b.

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

Backport of List.find_map from OCaml 4.10.

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

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

Sourceval drop : int -> 'a list -> 'a list

drop n l removes the first n elements of l if longer than n, else the empty list. Raise invalid_arg if n is negative.

Sourceval span : ('a -> bool) -> 'a list -> 'a list * 'a list

Split a list based on a predicate.

span f l returns a pair of lists (l1, l2), where l1 is the longest prefix of l that satisfies the predicate f, and l2 is the rest of the list. The order of the elements in the input list is preserved such that l = l1 @ l2.

Regular Expressions

Sourcetype rex

Compiled regular expressions.

Sourceval rex : ?opts:Re.Perl.opt list -> string -> rex

Compile a regular expression using Perl syntax.

Sourceval rexf : ?opts:Re.Perl.opt list -> ('a, unit, string, rex) format4 -> 'a

Same as rex @@ sf ....

Sourceval show_rex : rex -> string

Convert a regular expression to a string using Perl syntax.

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

Test whether a string matches a regular expression.

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

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

Negation of =~.

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

Match a regular expression with one capture group.

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

Match a regular expression with two capture groups.

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

Match a regular expression with three capture groups.

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

Match a regular expression with four capture groups.

Sourceval matches : string -> rex -> string list

Match a regular expression with one capture group and return all results.

Sourceval 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

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

Repeat something a given amount of times.

Sourceval fold : int -> 'a -> (int -> 'a -> 'a Lwt.t) -> 'a Lwt.t

Fold n times a given function.

Input/Output

Sourceval with_open_out : string -> (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

Sourceval with_open_in : string -> (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 *

Sourceval write_file : string -> contents:string -> unit

Write a string into a file, overwriting the file if it already exists.

Usage: write_file filename ~contents

Sourceval read_file : string -> string

Read the whole contents of a file.

Common structures

Sourcemodule String_map : Map.S with type key = string
Sourcemodule String_set : sig ... end

Environment

Sourceval project_root : string

Path to the root of the project.

This is DUNE_SOURCEROOT is defined, PWD otherwise.

OCaml

Innovation. Community. Security.