package tezt
Install
Dune Dependency
Authors
Maintainers
Sources
md5=d395cb9e663635ea8795f47c9bd9249f
sha512=d7c62899684ec202a98669eb575a2dc3bd1f8cf0430447c789a9d0aadc04a611d0dcfbcd7d61c613d4b7c78fd1bc4c533e4fcb48dbc8e3f19feaabe4ddd78723
doc/tezt.core/Tezt_core/Base/index.html
Module Tezt_core.Base
Source
Base functions.
Strings
Same as Filename.concat
.
Concurrency Monad
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.
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
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
.
Backport of List.find_map
from OCaml 4.10.
take n l
returns the first n
elements of l
if longer than n
, else l
itself.
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.
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
Compiled regular expressions.
Compile a regular expression using Perl syntax.
Same as rex @@ sf ...
.
Test whether a string matches a regular expression.
Example: "number 1234 matches" =~ rex "\\d+"
Match a regular expression with two capture groups.
Match a regular expression with three capture groups.
Match a regular expression with four capture groups.
Match a regular expression with one capture group and return all results.
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
Repeat something a given amount of times.
Input/Output
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
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 *
Write a string into a file, overwriting the file if it already exists.
Usage: write_file filename ~contents
Read the whole contents of a file.
Common structures
Environment
Path to the root of the project.
This is DUNE_SOURCEROOT
is defined, PWD
otherwise.