package tezt

  1. Overview
  2. Docs

Temporary file management.

Temporary files for tests.

val file : ?runner:Runner.t -> ?perms:Unix.file_perm -> string -> string

Get a temporary file name.

For instance:

  • file "hello.ml" may return something like "/tmp/tezt-1234/1/hello.ml";
  • file "some/dir/hello.ml" may return "/tmp/tezt-1234/1/some/dir/hello.ml";
  • file "/dir/hello.ml" may return "/tmp/tezt-1234/1/dir/hello.ml".

This function also creates the directory (and its parents) needed to host the resulting file.

perms is the permissions for parent directories if they are created. Default is 0o755, i.e. rwxr-xr-x.

If runner is specified, the temporary file is registered to be located in this remote runner, which means that it will be removed using SSH by the clean up function.

file base always returns the same result for a given base and for the same process.

val dir : ?runner:Runner.t -> ?perms:Unix.file_perm -> string -> string

Get a temporary file name and create it as a directory.

val set_pid : int -> unit

Set the current process identifier.

This affects the main temporary directory, e.g. "/tmp/tezt-1234" where 1234 is the PID set by set_pid.

The default PID if set_pid is not called is 0.

This is automatically called by Tezt.Test.run. This is, however, not called by Tezt_js.Test.run.

val start : unit -> string

Allow calls to file and dir until the next clean_up or stop.

Return the main temporary directory, e.g. "/tmp/tezt-1234/1", so that it can be displayed to users.

Calls to file and dir which are made before start result in an error.

Do not call this directly, it is called by Test.run. This prevents you from creating temporary files accidentally before your test actually runs. Indeed, if your test is disabled from the command-line it should not create temporary files. By using Test.run you also ensure that clean_up is called.

val stop : unit -> unit

Disallow calls to file and dir until the next start.

This can be called in place of clean_up if you want to keep temporary files.

val clean_up : unit -> unit

Delete temporary files and directories.

All files which were returned by file are deleted. All directories which were returned by dir are deleted, but only if they did not already exist. All parent directories that were created are then deleted, but only if they are empty.

OCaml

Innovation. Community. Security.