diff --git a/docs/reference/testo-lwt/Testo_lwt/index.html b/docs/reference/testo-lwt/Testo_lwt/index.html index 178d2be..ad5745f 100644 --- a/docs/reference/testo-lwt/Testo_lwt/index.html +++ b/docs/reference/testo-lwt/Testo_lwt/index.html @@ -1,12 +1,18 @@ -
Testo_lwtTesto library - Utilities for writing OCaml test suites
These types are documented in the library's source code in Types.ml. They are subject to frequent and unannounced changes at the whim of the library's authors. A casual user should not need them.
type expectation = {expected_outcome : expected_outcome;expected_output : (expected_output, missing_files) Stdlib.Result.t;}type passing_status = | PASS| FAIL of fail_reason| XFAIL of fail_reason| XPASS| MISS of missing_filestype status_summary = {passing_status : passing_status;outcome : outcome;has_expected_output : bool;}This type specifies what part of the output of a test (stdout, stderr) should be captured and compared against expectations.
Use the provided functions stdout, stderr, stdxxx, and split_stdout_stderr to create such an object.
val stdout : ?expected_stdout_path:Fpath.t -> unit -> checked_output_kindCreate an object of type checked_output_kind specifying that the test's standard output must be checked against a reference file.
val stderr : ?expected_stderr_path:Fpath.t -> unit -> checked_output_kindSame as stdout but for capturing stderr instead.
val stdxxx : ?expected_stdxxx_path:Fpath.t -> unit -> checked_output_kindSame as stdout but for capturing the combined stdout and stderr outputs.
val split_stdout_stderr :
+Testo_lwt (testo-lwt.Testo_lwt) Module Testo_lwt
Testo library - Utilities for writing OCaml test suites
Internal types
These types are documented in the library's source code in Types.ml. They are subject to frequent and unannounced changes at the whim of the library's authors. A casual user should not need them.
A test's output file whose contents captured from stdout or stderr should be checked and reported when it changes.
A test's output file that is produced by the test function, checked, and reported when it changes.
type result = {completion_status : completion_status;captured_output : captured_output;captured_output_files : checked_output_file_with_contents list;missing_output_files : Fpath.t list;
}type expectation = {expected_outcome : expected_outcome;expected_output : (expected_output, missing_files) Stdlib.Result.t;expected_output_files : (checked_output_file_with_contents, Fpath.t)
+ Stdlib.Result.t
+ list;
}type passing_status = | PASS| FAIL of fail_reason| XFAIL of fail_reason| XPASS| MISS of missing_files
type status_summary = {passing_status : passing_status;outcome : outcome;has_expected_output : bool;
}Main interface
Test creation
This type specifies what part of the output of a test (stdout, stderr) should be captured and compared against expectations.
Use the provided functions stdout, stderr, stdxxx, and split_stdout_stderr to create such an object.
val stdout : ?expected_stdout_path:Fpath.t -> unit -> checked_output_kindCreate an object of type checked_output_kind specifying that the test's standard output must be checked against a reference file.
val stderr : ?expected_stderr_path:Fpath.t -> unit -> checked_output_kindSame as stdout but for capturing stderr instead.
val stdxxx : ?expected_stdxxx_path:Fpath.t -> unit -> checked_output_kindSame as stdout but for capturing the combined stdout and stderr outputs.
val split_stdout_stderr :
?expected_stdout_path:Fpath.t ->
?expected_stderr_path:Fpath.t ->
unit ->
- checked_output_kindSame as stdxxx but keep stdout and stderr separate.
Wrapper allowing for asynchronous test functions (Lwt and such).
module Tag : module type of Testo_util.TagThe type of tags which can be used to define subsets of tests precisely.
type t = private {id : string;(*Hash of the full name of the test, computed automatically.
*)internal_full_name : string;(*Full name of the test, derived automatically from category and name.
*)category : string list;(*Categories are made for organizing tests as a tree which is useful for display and filtering. A new category is created typically when grouping multiple test suites into one with 'categorize_suites' or when assigning a category to a list of tests with 'categorize'. e.g. ["food"; "fruit"; "kiwi"]
*)name : string;func : unit -> unit Promise.t;broken : string option;(*If not None, the broken property causes the test to run normally but it will be ignored when determining the success of the test suite. This allows flaky tests to be kept around until they can be fixed. Use the string argument to explain briefly why the test is marked as broken. The --strict command-line option causes the broken status to be ignored i.e. a test run will fail if a broken test fails.
*)checked_output : checked_output_kind;expected_outcome : expected_outcome;max_duration : float option;(*A time limit for the test when running in a detached worker, in seconds. This setting is ignored when running tests sequentially in the master process such as with -j0 or in solo mode.
*)normalize : (string -> string) list;(*An optional function to rewrite any output data so as to mask the variable parts.
*)skipped : string option;(*If not None, the skipped property causes a test to be skipped by Alcotest but still shown as "[SKIP]" rather than being omitted. The string should give a reason why the test is being skipped.
*)solo : string option;(*If not None, this test will never run concurrently with other tests. The string should give a reason why the test should not run in parallel with other tests.
*)tolerate_chdir : bool;(*If the test function changes the current directory without restoring it, it's an error unless this flag is set. All the tests in a test suite should share this field. To change the current directory temporarily and safely, use with_chdir.
*)tracking_url : string option;(*A link to the relevant entry in a bug tracking system.
*)
}t is the type of a test. A test suite is a flat list of tests.
A test is at a minimum a name and a test function that raises exceptions to signal test failure. It is created with create or other similar functions provided by this module.
There are two main recommended ways of writing the test function:
1. With assert false:
Each test may use assert false to indicate that the test doesn't pass. This is the simplest way of failing while also showing the location of the failure. When using assert false, you should generally take care of printing the expected value and actual value to make debugging easier later.
2. With Alcotest.(check ...):
This is a little nicer because the error messages print something like "Expecting 'foo', got 'bar'". However, this can make tests slightly more complicated to write. If the test already prints the expected value and the actual value as its output, it's just easier to fail with assert false.
In any case, Alcotest will capture the output (stdout, stderr) of each test and put it in its own file so we can consult it later. Don't hesitate to log a lot during the execution of the test.
type test_with_status = t * status * status_summarytype subcommand_result = | Run_result of test_with_status list| Status_result of test_with_status list| Approve_result
The return type of each subcommand. It allows custom code to do something with the test data e.g. export to the JUnit format via the optional handle_subcommand_result argument of interpret_argv.
val create :
+ checked_output_kindSame as stdxxx but keep stdout and stderr separate.
val checked_output_file :
+ ?snapshot_path:Fpath.t ->
+ string ->
+ checked_output_filechecked_output_file name creates the specification for a checked output file identified by the name name. Popular names include "results.txt" and "results.json". name must be a nonempty sequence of ASCII letters, digits, underscores, dashes, or periods. Periods are not allowed in first or last position. It is used by Testo in messaging and in file names. The snapshot_path option specifies an alternate location for the snapshot file that serves as the expectation for future test runs.
stash_output_file src_path dst_name copies a checked output file of the current test identified by its name dst_name into Testo's status workspace.
This function must be called by the test function for each checked output file.
Wrapper allowing for asynchronous test functions (Lwt and such).
module Tag : module type of Testo_util.TagThe type of tags which can be used to define subsets of tests precisely.
type t = private {id : string;(*Hash of the full name of the test, computed automatically.
*)internal_full_name : string;(*Full name of the test, derived automatically from category and name.
*)category : string list;(*Categories are made for organizing tests as a tree which is useful for display and filtering. A new category is created typically when grouping multiple test suites into one with 'categorize_suites' or when assigning a category to a list of tests with 'categorize'. e.g. ["food"; "fruit"; "kiwi"]
*)name : string;func : unit -> unit Promise.t;broken : string option;(*If not None, the broken property causes the test to run normally but it will be ignored when determining the success of the test suite. This allows flaky tests to be kept around until they can be fixed. Use the string argument to explain briefly why the test is marked as broken. The --strict command-line option causes the broken status to be ignored i.e. a test run will fail if a broken test fails.
*)checked_output : checked_output_kind;checked_output_files : checked_output_file list;(*Files created by the test function whose contents must match a reference snapshot. The test function must copy its checked output files into Testo's workspace using stash_output_files.
*)expected_outcome : expected_outcome;max_duration : float option;(*A time limit for the test when running in a detached worker, in seconds. This setting is ignored when running tests sequentially in the master process such as with -j0 or in solo mode.
*)normalize : (string -> string) list;(*An optional function to rewrite any output data so as to mask the variable parts. This normalization is only applied to captured stdout or stderr, not to output files. If you wish to normalize output files, the test function should handle it, possibly with the provided map_file function.
*)skipped : string option;(*If not None, the skipped property causes a test to be skipped by Alcotest but still shown as "[SKIP]" rather than being omitted. The string should give a reason why the test is being skipped.
*)solo : string option;(*If not None, this test will never run concurrently with other tests. The string should give a reason why the test should not run in parallel with other tests.
*)tolerate_chdir : bool;(*If the test function changes the current directory without restoring it, it's an error unless this flag is set. All the tests in a test suite should share this field. To change the current directory temporarily and safely, use with_chdir.
*)tracking_url : string option;(*A link to the relevant entry in a bug tracking system.
*)
}t is the type of a test. A test suite is a flat list of tests.
A test is at a minimum a name and a test function that raises exceptions to signal test failure. It is created with create or other similar functions provided by this module.
There are two main recommended ways of writing the test function:
1. With assert false:
Each test may use assert false to indicate that the test doesn't pass. This is the simplest way of failing while also showing the location of the failure. When using assert false, you should generally take care of printing the expected value and actual value to make debugging easier later.
2. With Alcotest.(check ...):
This is a little nicer because the error messages print something like "Expecting 'foo', got 'bar'". However, this can make tests slightly more complicated to write. If the test already prints the expected value and the actual value as its output, it's just easier to fail with assert false.
In any case, Alcotest will capture the output (stdout, stderr) of each test and put it in its own file so we can consult it later. Don't hesitate to log a lot during the execution of the test.
type test_with_status = t * status * status_summarytype subcommand_result = | Run_result of test_with_status list| Status_result of test_with_status list| Approve_result
The return type of each subcommand. It allows custom code to do something with the test data e.g. export to the JUnit format via the optional handle_subcommand_result argument of interpret_argv.
val create :
?broken:string ->
?category:string list ->
?checked_output:checked_output_kind ->
+ ?checked_output_files:checked_output_file list ->
?expected_outcome:expected_outcome ->
?max_duration:float ->
?normalize:(string -> string) list ->
@@ -17,10 +23,11 @@
?tracking_url:string ->
string ->
(unit -> unit Promise.t) ->
- tCreate a test to appear in a test suite.
category: the nested category to assign to the test. The category can be nested further using categorize or categorize_suites.checked_output: determines how to capture the test's output. Defaults to no capture.expected_outcome: whether a test is expected to complete without raising an exception (default) or by raising an exception.max_duration: a time limit to run the test, in seconds. It is honored only in tests running in workers i.e. not with the -j0 option of the test program.normalize: a list of functions applied in turn to transform the captured output before comparing it to the reference snapshot. See mask_line and other functions with the mask prefix which are provided for this purpose.skipped: specify that the test must be skipped. This is intended for tests that give inconsistent results and need fixing. The string should explain why the test is being skipped. See also expected_outcome.solo: specify that the test may not run in concurrently with other tests. The string should explain why.tags: a list of tags to apply to the test. See Tag.tolerate_chdir: by default, a test will fail if it modifies the current directory and doesn't restore it. This flag cancels this check. Note that Testo will always restore the current directory after running a test regardless of this setting.
val update :
+ tCreate a test to appear in a test suite.
category: the nested category to assign to the test. The category can be nested further using categorize or categorize_suites.checked_output: determines how to capture the test's output. Defaults to no capture.checked_output_files: specifies the test's output files that should remain the same from one test run to another.expected_outcome: whether a test is expected to complete without raising an exception (default) or by raising an exception.max_duration: a time limit to run the test, in seconds. It is honored only in tests running in workers i.e. not with the -j0 option of the test program.normalize: a list of functions applied in turn to transform the captured output before comparing it to the reference snapshot. See mask_line and other functions with the mask prefix which are provided for this purpose.skipped: specify that the test must be skipped. This is intended for tests that give inconsistent results and need fixing. The string should explain why the test is being skipped. See also expected_outcome.solo: specify that the test may not run in concurrently with other tests. The string should explain why.tags: a list of tags to apply to the test. See Tag.tolerate_chdir: by default, a test will fail if it modifies the current directory and doesn't restore it. This flag cancels this check. Note that Testo will always restore the current directory after running a test regardless of this setting.
val update :
?broken:string option ->
?category:string list ->
?checked_output:checked_output_kind ->
+ ?checked_output_files:checked_output_file list ->
?expected_outcome:expected_outcome ->
?func:(unit -> unit Promise.t) ->
?max_duration:float option ->
@@ -32,7 +39,7 @@
?tolerate_chdir:bool ->
?tracking_url:string option ->
t ->
- tUpdate some of the test's fields. This ensures that the test's unique identifier id is recomputed correctly. When specified, an optional property will replace the previous value.
Assertions and exceptions
Signaling a test failure is done by raising an exception. You may raise any exception to signal a test failure.
At this time, Testo doesn't provide advanced functions for checking a result against an expected value and printing these values nicely. For these, you may want to use `Alcotest.check` from the alcotest library.
The exception raised by fail
Raise the Test_failure exception with a message indicating the reason for the failure.
Temporary files and output redirection
Write data to a regular file. Create the file if it doesn't exist. Erase any existing data.
Usage: write_file path data
val with_temp_file :
+ tUpdate some of the test's fields. This ensures that the test's unique identifier id is recomputed correctly. When specified, an optional property will replace the previous value.
Assertions and exceptions
Signaling a test failure is done by raising an exception. You may raise any exception to signal a test failure.
At this time, Testo doesn't provide advanced functions for checking a result against an expected value and printing these values nicely. For these, you may want to use `Alcotest.check` from the alcotest library.
The exception raised by fail
Raise the Test_failure exception with a message indicating the reason for the failure.
Temporary files and output redirection
Write data to a regular file. Create the file if it doesn't exist. Erase any existing data.
Usage: write_file path data
Read the contents of a regular file or symbolic link to a regular file.
map_file func src dst reads the contents of file (regular or symlink) src, applies func to its contents, and writes the result into file dst. If file dst already exists, it is truncated and overwritten. Otherwise, a regular file is created. If src and dst represent the same file, src will be overwritten with the new contents.
Copy a file. copy_file src dst is a shortcut for map_file (fun data -> data) src dst.
val with_temp_file :
?contents:string ->
?persist:bool ->
?prefix:string ->
@@ -45,7 +52,14 @@
('a * string) Promise.twith_capture stdout func evaluates func () while capturing the output of the given channel stdout as a string.
Environment control
with_environment_variables ["FOO", "42"; "BAR", "hello"] func sets the environment variables FOO and BAR during the execution of func and then restores them to their original values.
Additionally, a test failure is produced if func modifies these environment variables without restoring them to the state in which it found them.
Due to a limitation in OCaml's "Unix" library, environment variables cannot be unset. If an environment variable was originally unset, restoring this original state isn't possible. Instead, the environment variable will be set to the empty string when with_environment_variables returns.
with_chdir path func changes the current directory associated with the process to path before calling the function func. The original value of the current directory is restored when the function terminates.
Output masking functions
Functions with the mask_ prefix are string replacement utilities to be used for masking the variable parts of test output in order to make them stable and comparable. This is for the normalize option of create.
Testo will keep a copy of the original, unmasked output for the developer to consult. In particular, this masking functionality will not prevent sensitive data such as passwords or secret keys from being stored in the local file system.
val mask_line :
+ 'a Promise.twith_environment_variables ["FOO", "42"; "BAR", "hello"] func sets the environment variables FOO and BAR during the execution of func and then restores them to their original values.
Additionally, a test failure is produced if func modifies these environment variables without restoring them to the state in which it found them.
Due to a limitation in OCaml's "Unix" library, environment variables cannot be unset. If an environment variable was originally unset, restoring this original state isn't possible. Instead, the environment variable will be set to the empty string when with_environment_variables returns.
with_chdir path func changes the current directory associated with the process to path before calling the function func. The original value of the current directory is restored when the function returns or raises an exception.
val with_temp_dir :
+ ?chdir:bool ->
+ ?parent:Fpath.t ->
+ ?perms:int ->
+ ?prefix:string ->
+ ?suffix:string ->
+ (Fpath.t -> 'a) ->
+ 'awith_temp_dir func creates temporary folder dir, calls the function func dir and returns its result. dir and its contents are removed before with_temp_dir returns or raises an exception. If chdir is set to true, the current folder is set to dir during the execution of func (default: false). parent is the parent folder of the temporary folder to create and defaults to Filename.get_temp_dir_name (). perms is the Unix-style permission mask used when creating dir with Sys.mkdir or equivalent. prefix and suffix are a prefix and a suffix to use for the name of dir (defaults: unspecified and subject to change).
val get_current_test : unit -> t optionReturn the test currently running.
Output masking functions
Functions with the mask_ prefix are string replacement utilities to be used for masking the variable parts of test output in order to make them stable and comparable. This is for the normalize option of create.
Testo will keep a copy of the original, unmasked output for the developer to consult. In particular, this masking functionality will not prevent sensitive data such as passwords or secret keys from being stored in the local file system.
val mask_line :
?mask:string ->
?after:string ->
?before:string ->
diff --git a/docs/reference/testo-util/Testo_util/index.html b/docs/reference/testo-util/Testo_util/index.html
index 12b2206..577f918 100644
--- a/docs/reference/testo-util/Testo_util/index.html
+++ b/docs/reference/testo-util/Testo_util/index.html
@@ -1,2 +1,2 @@
-Testo_util (testo-util.Testo_util) Module Testo_util
module CPU : sig ... endmodule Debug : sig ... endmodule Diff : sig ... endmodule Error : sig ... endmodule Filename_ : sig ... endmodule Fpath_ : sig ... endmodule Helpers : sig ... endmodule Msg_from_master : sig ... endmodule Msg_from_worker : sig ... endmodule Multiprocess : sig ... endmodule Slice : sig ... endmodule Style : sig ... endmodule Tag : sig ... end
+Testo_util (testo-util.Testo_util) Module Testo_util
module CPU : sig ... endmodule Debug : sig ... endmodule Diff : sig ... endmodule Error : sig ... endmodule Filename_ : sig ... endmodule Fpath_ : sig ... endmodule Msg_from_master : sig ... endmodule Msg_from_worker : sig ... endmodule Multiprocess : sig ... endmodule Slice : sig ... endmodule Style : sig ... endmodule Tag : sig ... end
diff --git a/docs/reference/testo/Testo/index.html b/docs/reference/testo/Testo/index.html
index 30442ec..1ab8786 100644
--- a/docs/reference/testo/Testo/index.html
+++ b/docs/reference/testo/Testo/index.html
@@ -1,12 +1,18 @@
-Testo (testo.Testo) Module Testo
Testo library - Utilities for writing OCaml test suites
Internal types
These types are documented in the library's source code in Types.ml. They are subject to frequent and unannounced changes at the whim of the library's authors. A casual user should not need them.
type expectation = {expected_outcome : expected_outcome;expected_output : (expected_output, missing_files) Stdlib.Result.t;
}type passing_status = | PASS| FAIL of fail_reason| XFAIL of fail_reason| XPASS| MISS of missing_files
type status_summary = {passing_status : passing_status;outcome : outcome;has_expected_output : bool;
}Main interface
Test creation
This type specifies what part of the output of a test (stdout, stderr) should be captured and compared against expectations.
Use the provided functions stdout, stderr, stdxxx, and split_stdout_stderr to create such an object.
val stdout : ?expected_stdout_path:Fpath.t -> unit -> checked_output_kindCreate an object of type checked_output_kind specifying that the test's standard output must be checked against a reference file.
val stderr : ?expected_stderr_path:Fpath.t -> unit -> checked_output_kindSame as stdout but for capturing stderr instead.
val stdxxx : ?expected_stdxxx_path:Fpath.t -> unit -> checked_output_kindSame as stdout but for capturing the combined stdout and stderr outputs.
val split_stdout_stderr :
+Testo (testo.Testo) Module Testo
Testo library - Utilities for writing OCaml test suites
Internal types
These types are documented in the library's source code in Types.ml. They are subject to frequent and unannounced changes at the whim of the library's authors. A casual user should not need them.
A test's output file whose contents captured from stdout or stderr should be checked and reported when it changes.
A test's output file that is produced by the test function, checked, and reported when it changes.
type result = {completion_status : completion_status;captured_output : captured_output;captured_output_files : checked_output_file_with_contents list;missing_output_files : Fpath.t list;
}type expectation = {expected_outcome : expected_outcome;expected_output : (expected_output, missing_files) Stdlib.Result.t;expected_output_files : (checked_output_file_with_contents, Fpath.t)
+ Stdlib.Result.t
+ list;
}type passing_status = | PASS| FAIL of fail_reason| XFAIL of fail_reason| XPASS| MISS of missing_files
type status_summary = {passing_status : passing_status;outcome : outcome;has_expected_output : bool;
}Main interface
Test creation
This type specifies what part of the output of a test (stdout, stderr) should be captured and compared against expectations.
Use the provided functions stdout, stderr, stdxxx, and split_stdout_stderr to create such an object.
val stdout : ?expected_stdout_path:Fpath.t -> unit -> checked_output_kindCreate an object of type checked_output_kind specifying that the test's standard output must be checked against a reference file.
val stderr : ?expected_stderr_path:Fpath.t -> unit -> checked_output_kindSame as stdout but for capturing stderr instead.
val stdxxx : ?expected_stdxxx_path:Fpath.t -> unit -> checked_output_kindSame as stdout but for capturing the combined stdout and stderr outputs.
val split_stdout_stderr :
?expected_stdout_path:Fpath.t ->
?expected_stderr_path:Fpath.t ->
unit ->
- checked_output_kindSame as stdxxx but keep stdout and stderr separate.
Wrapper allowing for asynchronous test functions (Lwt and such).
module Tag : module type of Testo_util.TagThe type of tags which can be used to define subsets of tests precisely.
type t = private {id : string;(*Hash of the full name of the test, computed automatically.
*)internal_full_name : string;(*Full name of the test, derived automatically from category and name.
*)category : string list;(*Categories are made for organizing tests as a tree which is useful for display and filtering. A new category is created typically when grouping multiple test suites into one with 'categorize_suites' or when assigning a category to a list of tests with 'categorize'. e.g. ["food"; "fruit"; "kiwi"]
*)name : string;func : unit -> unit Promise.t;broken : string option;(*If not None, the broken property causes the test to run normally but it will be ignored when determining the success of the test suite. This allows flaky tests to be kept around until they can be fixed. Use the string argument to explain briefly why the test is marked as broken. The --strict command-line option causes the broken status to be ignored i.e. a test run will fail if a broken test fails.
*)checked_output : checked_output_kind;expected_outcome : expected_outcome;max_duration : float option;(*A time limit for the test when running in a detached worker, in seconds. This setting is ignored when running tests sequentially in the master process such as with -j0 or in solo mode.
*)normalize : (string -> string) list;(*An optional function to rewrite any output data so as to mask the variable parts.
*)skipped : string option;(*If not None, the skipped property causes a test to be skipped by Alcotest but still shown as "[SKIP]" rather than being omitted. The string should give a reason why the test is being skipped.
*)solo : string option;(*If not None, this test will never run concurrently with other tests. The string should give a reason why the test should not run in parallel with other tests.
*)tolerate_chdir : bool;(*If the test function changes the current directory without restoring it, it's an error unless this flag is set. All the tests in a test suite should share this field. To change the current directory temporarily and safely, use with_chdir.
*)tracking_url : string option;(*A link to the relevant entry in a bug tracking system.
*)
}t is the type of a test. A test suite is a flat list of tests.
A test is at a minimum a name and a test function that raises exceptions to signal test failure. It is created with create or other similar functions provided by this module.
There are two main recommended ways of writing the test function:
1. With assert false:
Each test may use assert false to indicate that the test doesn't pass. This is the simplest way of failing while also showing the location of the failure. When using assert false, you should generally take care of printing the expected value and actual value to make debugging easier later.
2. With Alcotest.(check ...):
This is a little nicer because the error messages print something like "Expecting 'foo', got 'bar'". However, this can make tests slightly more complicated to write. If the test already prints the expected value and the actual value as its output, it's just easier to fail with assert false.
In any case, Alcotest will capture the output (stdout, stderr) of each test and put it in its own file so we can consult it later. Don't hesitate to log a lot during the execution of the test.
type test_with_status = t * status * status_summarytype subcommand_result = | Run_result of test_with_status list| Status_result of test_with_status list| Approve_result
The return type of each subcommand. It allows custom code to do something with the test data e.g. export to the JUnit format via the optional handle_subcommand_result argument of interpret_argv.
val create :
+ checked_output_kindSame as stdxxx but keep stdout and stderr separate.
val checked_output_file :
+ ?snapshot_path:Fpath.t ->
+ string ->
+ checked_output_filechecked_output_file name creates the specification for a checked output file identified by the name name. Popular names include "results.txt" and "results.json". name must be a nonempty sequence of ASCII letters, digits, underscores, dashes, or periods. Periods are not allowed in first or last position. It is used by Testo in messaging and in file names. The snapshot_path option specifies an alternate location for the snapshot file that serves as the expectation for future test runs.
stash_output_file src_path dst_name copies a checked output file of the current test identified by its name dst_name into Testo's status workspace.
This function must be called by the test function for each checked output file.
Wrapper allowing for asynchronous test functions (Lwt and such).
module Tag : module type of Testo_util.TagThe type of tags which can be used to define subsets of tests precisely.
type t = private {id : string;(*Hash of the full name of the test, computed automatically.
*)internal_full_name : string;(*Full name of the test, derived automatically from category and name.
*)category : string list;(*Categories are made for organizing tests as a tree which is useful for display and filtering. A new category is created typically when grouping multiple test suites into one with 'categorize_suites' or when assigning a category to a list of tests with 'categorize'. e.g. ["food"; "fruit"; "kiwi"]
*)name : string;func : unit -> unit Promise.t;broken : string option;(*If not None, the broken property causes the test to run normally but it will be ignored when determining the success of the test suite. This allows flaky tests to be kept around until they can be fixed. Use the string argument to explain briefly why the test is marked as broken. The --strict command-line option causes the broken status to be ignored i.e. a test run will fail if a broken test fails.
*)checked_output : checked_output_kind;checked_output_files : checked_output_file list;(*Files created by the test function whose contents must match a reference snapshot. The test function must copy its checked output files into Testo's workspace using stash_output_files.
*)expected_outcome : expected_outcome;max_duration : float option;(*A time limit for the test when running in a detached worker, in seconds. This setting is ignored when running tests sequentially in the master process such as with -j0 or in solo mode.
*)normalize : (string -> string) list;(*An optional function to rewrite any output data so as to mask the variable parts. This normalization is only applied to captured stdout or stderr, not to output files. If you wish to normalize output files, the test function should handle it, possibly with the provided map_file function.
*)skipped : string option;(*If not None, the skipped property causes a test to be skipped by Alcotest but still shown as "[SKIP]" rather than being omitted. The string should give a reason why the test is being skipped.
*)solo : string option;(*If not None, this test will never run concurrently with other tests. The string should give a reason why the test should not run in parallel with other tests.
*)tolerate_chdir : bool;(*If the test function changes the current directory without restoring it, it's an error unless this flag is set. All the tests in a test suite should share this field. To change the current directory temporarily and safely, use with_chdir.
*)tracking_url : string option;(*A link to the relevant entry in a bug tracking system.
*)
}t is the type of a test. A test suite is a flat list of tests.
A test is at a minimum a name and a test function that raises exceptions to signal test failure. It is created with create or other similar functions provided by this module.
There are two main recommended ways of writing the test function:
1. With assert false:
Each test may use assert false to indicate that the test doesn't pass. This is the simplest way of failing while also showing the location of the failure. When using assert false, you should generally take care of printing the expected value and actual value to make debugging easier later.
2. With Alcotest.(check ...):
This is a little nicer because the error messages print something like "Expecting 'foo', got 'bar'". However, this can make tests slightly more complicated to write. If the test already prints the expected value and the actual value as its output, it's just easier to fail with assert false.
In any case, Alcotest will capture the output (stdout, stderr) of each test and put it in its own file so we can consult it later. Don't hesitate to log a lot during the execution of the test.
type test_with_status = t * status * status_summarytype subcommand_result = | Run_result of test_with_status list| Status_result of test_with_status list| Approve_result
The return type of each subcommand. It allows custom code to do something with the test data e.g. export to the JUnit format via the optional handle_subcommand_result argument of interpret_argv.
val create :
?broken:string ->
?category:string list ->
?checked_output:checked_output_kind ->
+ ?checked_output_files:checked_output_file list ->
?expected_outcome:expected_outcome ->
?max_duration:float ->
?normalize:(string -> string) list ->
@@ -17,10 +23,11 @@
?tracking_url:string ->
string ->
(unit -> unit Promise.t) ->
- tCreate a test to appear in a test suite.
category: the nested category to assign to the test. The category can be nested further using categorize or categorize_suites.checked_output: determines how to capture the test's output. Defaults to no capture.expected_outcome: whether a test is expected to complete without raising an exception (default) or by raising an exception.max_duration: a time limit to run the test, in seconds. It is honored only in tests running in workers i.e. not with the -j0 option of the test program.normalize: a list of functions applied in turn to transform the captured output before comparing it to the reference snapshot. See mask_line and other functions with the mask prefix which are provided for this purpose.skipped: specify that the test must be skipped. This is intended for tests that give inconsistent results and need fixing. The string should explain why the test is being skipped. See also expected_outcome.solo: specify that the test may not run in concurrently with other tests. The string should explain why.tags: a list of tags to apply to the test. See Tag.tolerate_chdir: by default, a test will fail if it modifies the current directory and doesn't restore it. This flag cancels this check. Note that Testo will always restore the current directory after running a test regardless of this setting.
val update :
+ tCreate a test to appear in a test suite.
category: the nested category to assign to the test. The category can be nested further using categorize or categorize_suites.checked_output: determines how to capture the test's output. Defaults to no capture.checked_output_files: specifies the test's output files that should remain the same from one test run to another.expected_outcome: whether a test is expected to complete without raising an exception (default) or by raising an exception.max_duration: a time limit to run the test, in seconds. It is honored only in tests running in workers i.e. not with the -j0 option of the test program.normalize: a list of functions applied in turn to transform the captured output before comparing it to the reference snapshot. See mask_line and other functions with the mask prefix which are provided for this purpose.skipped: specify that the test must be skipped. This is intended for tests that give inconsistent results and need fixing. The string should explain why the test is being skipped. See also expected_outcome.solo: specify that the test may not run in concurrently with other tests. The string should explain why.tags: a list of tags to apply to the test. See Tag.tolerate_chdir: by default, a test will fail if it modifies the current directory and doesn't restore it. This flag cancels this check. Note that Testo will always restore the current directory after running a test regardless of this setting.
val update :
?broken:string option ->
?category:string list ->
?checked_output:checked_output_kind ->
+ ?checked_output_files:checked_output_file list ->
?expected_outcome:expected_outcome ->
?func:(unit -> unit Promise.t) ->
?max_duration:float option ->
@@ -32,7 +39,7 @@
?tolerate_chdir:bool ->
?tracking_url:string option ->
t ->
- tUpdate some of the test's fields. This ensures that the test's unique identifier id is recomputed correctly. When specified, an optional property will replace the previous value.
Assertions and exceptions
Signaling a test failure is done by raising an exception. You may raise any exception to signal a test failure.
At this time, Testo doesn't provide advanced functions for checking a result against an expected value and printing these values nicely. For these, you may want to use `Alcotest.check` from the alcotest library.
The exception raised by fail
Raise the Test_failure exception with a message indicating the reason for the failure.
Temporary files and output redirection
Write data to a regular file. Create the file if it doesn't exist. Erase any existing data.
Usage: write_file path data
val with_temp_file :
+ tUpdate some of the test's fields. This ensures that the test's unique identifier id is recomputed correctly. When specified, an optional property will replace the previous value.
Assertions and exceptions
Signaling a test failure is done by raising an exception. You may raise any exception to signal a test failure.
At this time, Testo doesn't provide advanced functions for checking a result against an expected value and printing these values nicely. For these, you may want to use `Alcotest.check` from the alcotest library.
The exception raised by fail
Raise the Test_failure exception with a message indicating the reason for the failure.
Temporary files and output redirection
Write data to a regular file. Create the file if it doesn't exist. Erase any existing data.
Usage: write_file path data
Read the contents of a regular file or symbolic link to a regular file.
map_file func src dst reads the contents of file (regular or symlink) src, applies func to its contents, and writes the result into file dst. If file dst already exists, it is truncated and overwritten. Otherwise, a regular file is created. If src and dst represent the same file, src will be overwritten with the new contents.
Copy a file. copy_file src dst is a shortcut for map_file (fun data -> data) src dst.
val with_temp_file :
?contents:string ->
?persist:bool ->
?prefix:string ->
@@ -45,7 +52,14 @@
('a * string) Promise.twith_capture stdout func evaluates func () while capturing the output of the given channel stdout as a string.
Environment control
with_environment_variables ["FOO", "42"; "BAR", "hello"] func sets the environment variables FOO and BAR during the execution of func and then restores them to their original values.
Additionally, a test failure is produced if func modifies these environment variables without restoring them to the state in which it found them.
Due to a limitation in OCaml's "Unix" library, environment variables cannot be unset. If an environment variable was originally unset, restoring this original state isn't possible. Instead, the environment variable will be set to the empty string when with_environment_variables returns.
with_chdir path func changes the current directory associated with the process to path before calling the function func. The original value of the current directory is restored when the function terminates.
Output masking functions
Functions with the mask_ prefix are string replacement utilities to be used for masking the variable parts of test output in order to make them stable and comparable. This is for the normalize option of create.
Testo will keep a copy of the original, unmasked output for the developer to consult. In particular, this masking functionality will not prevent sensitive data such as passwords or secret keys from being stored in the local file system.
val mask_line :
+ 'a Promise.twith_environment_variables ["FOO", "42"; "BAR", "hello"] func sets the environment variables FOO and BAR during the execution of func and then restores them to their original values.
Additionally, a test failure is produced if func modifies these environment variables without restoring them to the state in which it found them.
Due to a limitation in OCaml's "Unix" library, environment variables cannot be unset. If an environment variable was originally unset, restoring this original state isn't possible. Instead, the environment variable will be set to the empty string when with_environment_variables returns.
with_chdir path func changes the current directory associated with the process to path before calling the function func. The original value of the current directory is restored when the function returns or raises an exception.
val with_temp_dir :
+ ?chdir:bool ->
+ ?parent:Fpath.t ->
+ ?perms:int ->
+ ?prefix:string ->
+ ?suffix:string ->
+ (Fpath.t -> 'a) ->
+ 'awith_temp_dir func creates temporary folder dir, calls the function func dir and returns its result. dir and its contents are removed before with_temp_dir returns or raises an exception. If chdir is set to true, the current folder is set to dir during the execution of func (default: false). parent is the parent folder of the temporary folder to create and defaults to Filename.get_temp_dir_name (). perms is the Unix-style permission mask used when creating dir with Sys.mkdir or equivalent. prefix and suffix are a prefix and a suffix to use for the name of dir (defaults: unspecified and subject to change).
val get_current_test : unit -> t optionReturn the test currently running.
Output masking functions
Functions with the mask_ prefix are string replacement utilities to be used for masking the variable parts of test output in order to make them stable and comparable. This is for the normalize option of create.
Testo will keep a copy of the original, unmasked output for the developer to consult. In particular, this masking functionality will not prevent sensitive data such as passwords or secret keys from being stored in the local file system.